home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1993 May / Info-Mac_II_May_1993.to_.sit / Info-Mac II (May 1993).toast / Unix / Macutil-20b1.shar < prev    next >
Text File  |  1993-01-10  |  405KB  |  15,874 lines

  1. #! /bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #! /bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create:
  6. #    macutil
  7. # This archive created: Mon Apr 27 02:10:27 1992
  8. export PATH; PATH=/bin:/usr/bin:$PATH
  9. if test ! -d 'macutil'
  10. then
  11.     echo shar: "creating directory 'macutil'"
  12.     mkdir 'macutil'
  13. fi
  14. echo shar: "entering directory 'macutil'"
  15. cd 'macutil'
  16. if test ! -d 'crc'
  17. then
  18.     echo shar: "creating directory 'crc'"
  19.     mkdir 'crc'
  20. fi
  21. echo shar: "entering directory 'crc'"
  22. cd 'crc'
  23. echo shar: "extracting 'makecrc.c'" '(4416 characters)'
  24. if test -f 'makecrc.c'
  25. then
  26.     echo shar: "will not over-write existing file 'makecrc.c'"
  27. else
  28. sed 's/^X//' << \SHAR_EOF > 'makecrc.c'
  29. X/* This program will write six C routines for the calculation of
  30. X * the following CRC's. */
  31. X
  32. X/* The CRC polynomial.
  33. X * These 4 values define the crc-polynomial.
  34. X * If you change them, you must change crctab[]'s initial value to what is
  35. X * printed by initcrctab() [see 'compile with -DMAKETAB' above].
  36. X */
  37. X
  38. X/* This tables assumes CCITT is MSB first.  Swapped means LSB first.   In that
  39. X * case the polynomial is also swapped
  40. X */
  41. X
  42. X/* 16 bit crc's */
  43. X/* Value used by:            CCITT    KERMIT    ARC    BINHEX    */
  44. X/* the poly:                0x1021    0x8408    0xA001    0x1021    */
  45. X/* original:                0x1021    0x1021    0x8005    0x1021    */
  46. X/* init value:                -1    0    0    0    */
  47. X/* swapped:                no    yes    yes    no    */
  48. X/* bits in CRC:                16    16    16    16    */
  49. X/* ARC used by LHARC, ZOO, STUFFIT                    */
  50. X/* BINHEX used by XMODEM, PACKIT                    */
  51. X
  52. X/* 32 bit crc's */
  53. X/* Value used by:            CCITT32        ZIP        */
  54. X/* the poly:                0x04c11db7    0xedb88320    */
  55. X/* original:                0x04c11db7    0x04c11db7    */
  56. X/* init value:                -1        -1        */
  57. X/* swapped                no        yes        */
  58. X/* bits in CRC:                32        32        */
  59. X/* ZIP used by COMPACTOR                        */
  60. X
  61. X#include <stdio.h>
  62. X
  63. Xextern void exit();
  64. Xextern char *strcat();
  65. X
  66. Xstatic void initcrctab();
  67. X
  68. Xmain()
  69. X{
  70. X    initcrctab("ccitt", 0x1021, 0xffff, 0, 16);
  71. X    initcrctab("kermit", 0x8408, 0, 1, 16);
  72. X    initcrctab("arc", 0xa001, 0, 1, 16);
  73. X    initcrctab("binhex", 0x1021, 0, 0, 16);
  74. X    initcrctab("ccitt32",0x04c11db7,0xffffffff,0,32);
  75. X    initcrctab("zip",0xedb88320,0xffffffff,1,32);
  76. X    exit(0);
  77. X    /*NOTREACHED*/
  78. X}
  79. X
  80. Xstatic void initcrctab(name, poly, init, swapped, bits)
  81. Xchar *name;
  82. Xint poly, init, swapped, bits;
  83. X{
  84. X    register  int b, i;
  85. X    unsigned short v;
  86. X    unsigned long vv;
  87. X    FILE *fd;
  88. X    char buf[20];
  89. X    
  90. X    buf[0] = 0;
  91. X    (void)strcat(buf, name);
  92. X    (void)strcat(buf, ".c");
  93. X    if((fd = fopen(buf, "w")) == NULL) {
  94. X    (void)fprintf(stderr, "Cannot open %s for writing\n", buf);
  95. X    exit(1);
  96. X    }
  97. X    (void)fprintf(fd, "unsigned long %s_crcinit = %d;\n", name, init);
  98. X    (void)fprintf(fd, "\n");
  99. X    if(bits == 16) {
  100. X    (void)fprintf(fd, "static unsigned short crctab[256] = {\n");
  101. X    } else {
  102. X    (void)fprintf(fd, "static unsigned long crctab[256] = {\n");
  103. X    }
  104. X    (void)fprintf(fd, "    ");
  105. X    if(bits == 16) {
  106. X    for(b = 0; b < 256; ++b) {
  107. X        if(swapped) {
  108. X        for(v = b, i = 8; --i >= 0;)
  109. X            v = v & 1 ? (v>>1)^poly : v>>1;
  110. X        } else {
  111. X        for(v = b<<8, i = 8; --i >= 0;)
  112. X            v = v & 0x8000 ? (v<<1)^poly : v<<1;
  113. X        }
  114. X        (void)fprintf(fd, "0x%.4x,", v & 0xffff);
  115. X        if((b&7) == 7) {
  116. X        (void)fprintf(fd, "\n");
  117. X        if(b != 255) (void)fprintf(fd, "    ");
  118. X        } else {
  119. X        (void)fprintf(fd, " ");
  120. X        }
  121. X    }
  122. X    } else {
  123. X    for(b = 0; b < 256; ++b) {
  124. X        if(swapped) {
  125. X        for(vv = b, i = 8; --i >= 0;)
  126. X            vv = vv & 1 ? (vv>>1)^poly : vv>>1;
  127. X        } else {
  128. X        for(vv = b<<24, i = 8; --i >= 0;)
  129. X            vv = vv & 0x80000000 ? (vv<<1)^poly : vv<<1;
  130. X        }
  131. X        (void)fprintf(fd, "0x%.8x,", vv & 0xffffffff);
  132. X        if((b&3) == 3) {
  133. X        (void)fprintf(fd, "\n");
  134. X        if(b != 255) (void)fprintf(fd, "    ");
  135. X        } else {
  136. X        (void)fprintf(fd, " ");
  137. X        }
  138. X    }
  139. X    }
  140. X    (void)fprintf(fd, "};\n");
  141. X    (void)fprintf(fd, "\n");
  142. X    (void)fprintf(fd, "unsigned long %s_updcrc(icrc, icp, icnt)\n", name);
  143. X    (void)fprintf(fd, "    unsigned long icrc;\n");
  144. X    (void)fprintf(fd, "    unsigned char *icp;\n");
  145. X    (void)fprintf(fd, "    int icnt;\n");
  146. X    (void)fprintf(fd, "{\n");
  147. X    if(bits == 16) {
  148. X    (void)fprintf(fd, "#define M1 0xff\n");
  149. X    (void)fprintf(fd, "#define M2 0xff00\n");
  150. X    } else {
  151. X    (void)fprintf(fd, "#define M1 0xffffff\n");
  152. X    (void)fprintf(fd, "#define M2 0xffffff00\n");
  153. X    }
  154. X    (void)fprintf(fd, "    register unsigned long crc = icrc;\n");
  155. X    (void)fprintf(fd, "    register unsigned char *cp = icp;\n");
  156. X    (void)fprintf(fd, "    register int cnt = icnt;\n");
  157. X    (void)fprintf(fd, "\n");
  158. X    (void)fprintf(fd, "    while(cnt--) {\n");
  159. X    if(bits == 16) {
  160. X    if (swapped) {
  161. X        (void)fprintf(fd,
  162. X            "\tcrc=((crc>>8)&M1)^crctab[(crc&0xff)^*cp++];\n");
  163. X    } else {
  164. X        (void)fprintf(fd,
  165. X            "\tcrc=((crc<<8)&M2)^crctab[((crc>>8)&0xff)^*cp++];\n");
  166. X    }
  167. X    } else {
  168. X    if(swapped) {
  169. X        (void)fprintf(fd,
  170. X            "\tcrc=((crc>>8)&M1)^crctab[(crc&0xff)^*cp++];\n");
  171. X    } else {
  172. X        (void)fprintf(fd,
  173. X            "\tcrc=((crc<<8)&M2)^crctab[((crc>>24)&0xff)^*cp++];\n");
  174. X    }
  175. X    }
  176. X    (void)fprintf(fd, "    }\n");
  177. X    (void)fprintf(fd, "\n");
  178. X    (void)fprintf(fd, "    return(crc);\n");
  179. X    (void)fprintf(fd, "}\n");
  180. X    (void)fprintf(fd, "\n");
  181. X    (void)fclose(fd);
  182. X}
  183. X
  184. SHAR_EOF
  185. if test 4416 -ne "`wc -c < 'makecrc.c'`"
  186. then
  187.     echo shar: "error transmitting 'makecrc.c'" '(should have been 4416 characters)'
  188. fi
  189. fi
  190. echo shar: "extracting 'makefile'" '(475 characters)'
  191. if test -f 'makefile'
  192. then
  193.     echo shar: "will not over-write existing file 'makefile'"
  194. else
  195. sed 's/^X//' << \SHAR_EOF > 'makefile'
  196. XCFLAGS =    -O $(CF)
  197. XCRCC =    arc.c ccitt.c kermit.c binhex.c ccitt32.c zip.c
  198. XCRCO =    arc.o ccitt.o kermit.o binhex.o ccitt32.o zip.o
  199. X
  200. Xlibcrc.a:    $(CRCO)
  201. X    ar r libcrc.a $(CRCO)
  202. X    if test -f /usr/bin/ranlib ;\
  203. X    then \
  204. X        ranlib libcrc.a ;\
  205. X    fi
  206. X
  207. Xclean:
  208. X    -rm -f $(CRCC) $(CRCO) libcrc.a makecrc makecrc.o
  209. X
  210. X$(CRCC):    makecrc
  211. X    ./makecrc
  212. X
  213. Xmakecrc:    makecrc.o
  214. X    cc -O -o makecrc makecrc.o
  215. X
  216. Xarc.o:    arc.c
  217. Xccitt.o:    ccitt.c
  218. Xkermit.o:    kermit.c
  219. Xbinhex.o:    binhex.c
  220. Xccitt32.o:    ccitt32.c
  221. Xzip.o:        zip.c
  222. X
  223. SHAR_EOF
  224. if test 475 -ne "`wc -c < 'makefile'`"
  225. then
  226.     echo shar: "error transmitting 'makefile'" '(should have been 475 characters)'
  227. fi
  228. fi
  229. echo shar: "done with directory 'crc'"
  230. cd ..
  231. if test ! -d 'fileio'
  232. then
  233.     echo shar: "creating directory 'fileio'"
  234.     mkdir 'fileio'
  235. fi
  236. echo shar: "entering directory 'fileio'"
  237. cd 'fileio'
  238. echo shar: "extracting 'wrfile.h'" '(289 characters)'
  239. if test -f 'wrfile.h'
  240. then
  241.     echo shar: "will not over-write existing file 'wrfile.h'"
  242. else
  243. sed 's/^X//' << \SHAR_EOF > 'wrfile.h'
  244. Xextern char *out_buffer, *out_ptr;
  245. X
  246. Xextern void define_name();
  247. Xextern void start_info();
  248. Xextern void start_rsrc();
  249. Xextern void start_data();
  250. Xextern void end_file();
  251. X#ifdef SCAN
  252. Xextern void do_idf();
  253. X#endif /* SCAN */
  254. Xextern void do_mkdir();
  255. Xextern void enddir();
  256. Xextern char *get_mina();
  257. X
  258. SHAR_EOF
  259. if test 289 -ne "`wc -c < 'wrfile.h'`"
  260. then
  261.     echo shar: "error transmitting 'wrfile.h'" '(should have been 289 characters)'
  262. fi
  263. fi
  264. echo shar: "extracting 'wrfileopt.h'" '(145 characters)'
  265. if test -f 'wrfileopt.h'
  266. then
  267.     echo shar: "will not over-write existing file 'wrfileopt.h'"
  268. else
  269. sed 's/^X//' << \SHAR_EOF > 'wrfileopt.h'
  270. Xextern int wrfileopt();
  271. Xextern void give_wrfileopt();
  272. Xextern void set_wrfileopt();
  273. Xextern void set_s_wrfileopt();
  274. Xextern char *get_wrfileopt();
  275. X
  276. SHAR_EOF
  277. if test 145 -ne "`wc -c < 'wrfileopt.h'`"
  278. then
  279.     echo shar: "error transmitting 'wrfileopt.h'" '(should have been 145 characters)'
  280. fi
  281. fi
  282. echo shar: "extracting 'fileglob.h'" '(39 characters)'
  283. if test -f 'fileglob.h'
  284. then
  285.     echo shar: "will not over-write existing file 'fileglob.h'"
  286. else
  287. sed 's/^X//' << \SHAR_EOF > 'fileglob.h'
  288. Xextern int bytes_read, bytes_written;
  289. X
  290. SHAR_EOF
  291. if test 39 -ne "`wc -c < 'fileglob.h'`"
  292. then
  293.     echo shar: "error transmitting 'fileglob.h'" '(should have been 39 characters)'
  294. fi
  295. fi
  296. echo shar: "extracting 'makefile'" '(556 characters)'
  297. if test -f 'makefile'
  298. then
  299.     echo shar: "will not over-write existing file 'makefile'"
  300. else
  301. sed 's/^X//' << \SHAR_EOF > 'makefile'
  302. XCFLAGS=    -O $(CF)
  303. X
  304. Xall:    wrfile.o rdfile.o fileglob.o
  305. X    touch all
  306. X
  307. Xwrfile.o:    wrfile.c
  308. X
  309. Xrdfile.o:    rdfile.c
  310. X
  311. Xclean:
  312. X    -rm -f wrfile.o
  313. X    -rm -f rdfile.o
  314. X    -rm -f fileglob.o
  315. X    -rm -f all
  316. X
  317. Xwrfile.o:    machdr.h
  318. Xwrfile.o:    wrfile.h
  319. Xwrfile.o:    wrfileopt.h
  320. Xwrfile.o:    fileglob.h
  321. Xwrfile.o:    aufs.h
  322. Xwrfile.o:    appledouble.h
  323. Xwrfile.o:    ../util/util.h
  324. Xwrfile.o:    ../util/curtime.h
  325. Xrdfile.o:    machdr.h
  326. Xrdfile.o:    rdfile.h
  327. Xrdfile.o:    rdfileopt.h
  328. Xrdfile.o:    ../util/util.h
  329. Xrdfile.o:    ../util/curtime.h
  330. Xrdfile.o:    ../util/masks.h
  331. Xrdfile.o:    aufs.h
  332. Xrdfile.o:    appledouble.h
  333. Xfileglob.o:    fileglob.h
  334. X
  335. SHAR_EOF
  336. if test 556 -ne "`wc -c < 'makefile'`"
  337. then
  338.     echo shar: "error transmitting 'makefile'" '(should have been 556 characters)'
  339. fi
  340. fi
  341. echo shar: "extracting 'machdr.h'" '(432 characters)'
  342. if test -f 'machdr.h'
  343. then
  344.     echo shar: "will not over-write existing file 'machdr.h'"
  345. else
  346. sed 's/^X//' << \SHAR_EOF > 'machdr.h'
  347. X#define INFOBYTES 128
  348. X
  349. X/* The following are copied out of macput.c/macget.c */
  350. X#define I_NAMEOFF 1
  351. X/* 65 <-> 80 is the FInfo structure */
  352. X#define I_TYPEOFF 65
  353. X#define I_AUTHOFF 69
  354. X#define I_FLAGOFF 73
  355. X#define I_LOCKOFF 81
  356. X#define I_DLENOFF 83
  357. X#define I_RLENOFF 87
  358. X#define I_CTIMOFF 91
  359. X#define I_MTIMOFF 95
  360. X
  361. X#define F_NAMELEN 63
  362. X#define I_NAMELEN 69    /* 63 + strlen(".info") + 1 */
  363. X
  364. X#define INITED_MASK    1
  365. X#define PROTCT_MASK    0x40
  366. X
  367. SHAR_EOF
  368. if test 432 -ne "`wc -c < 'machdr.h'`"
  369. then
  370.     echo shar: "error transmitting 'machdr.h'" '(should have been 432 characters)'
  371. fi
  372. fi
  373. echo shar: "extracting 'wrfile.c'" '(19424 characters)'
  374. if test -f 'wrfile.c'
  375. then
  376.     echo shar: "will not over-write existing file 'wrfile.c'"
  377. else
  378. sed 's/^X//' << \SHAR_EOF > 'wrfile.c'
  379. X#ifdef TYPES_H
  380. X#include <sys/types.h>
  381. X#endif /* TYPES_H */
  382. X#include <sys/stat.h>
  383. X#include <ctype.h>
  384. X#include <stdio.h>
  385. X#include "machdr.h"
  386. X#include "wrfile.h"
  387. X#include "wrfileopt.h"
  388. X#include "../util/util.h"
  389. X#ifdef AUFSPLUS
  390. X#include "../util/curtime.h"
  391. X#define AUFS
  392. X#endif /* AUFSPLUS */
  393. X#ifdef AUFS
  394. X#include "aufs.h"
  395. X#define APPLESHARE
  396. X#endif /* AUFS */
  397. X#ifdef APPLEDOUBLE
  398. X#include "appledouble.h"
  399. X#include "../util/curtime.h"
  400. X#define APPLESHARE
  401. X#endif /* APPLEDOUBLE */
  402. X
  403. X#define TEXT 0
  404. X#define DATA 1
  405. X#define RSRC 2
  406. X#define FULL 3
  407. X#define MACB 4
  408. X#define FORK 5
  409. X#define APSH 6
  410. X#define MACS 7
  411. X#define UNIX 8
  412. X#ifdef SCAN
  413. X#define MACI 9
  414. X#endif /* SCAN */
  415. X
  416. Xextern char *malloc();
  417. Xextern char *realloc();
  418. Xextern char *strcpy();
  419. Xextern char *strncpy();
  420. Xextern char *strcat();
  421. Xextern void exit();
  422. X
  423. X#ifdef UNDEF /* Do not declare sprintf; not portable (but lint will complain) */
  424. Xchar *sprintf();
  425. X#endif /* UNDEF */
  426. X
  427. X#ifdef AUFS
  428. Xstatic void check_aufs();
  429. Xstatic void aufs_namings();
  430. Xstatic void wr_aufs_info();
  431. X#endif /* AUFS */
  432. X#ifdef APPLEDOUBLE
  433. Xstatic void check_appledouble();
  434. Xstatic void appledouble_namings();
  435. Xstatic void wr_appledouble_info();
  436. X#endif /* APPLEDOUBLE */
  437. X#ifdef APPLESHARE
  438. Xstatic void mk_share_name();
  439. X#endif /* APPLESHARE */
  440. X
  441. X#ifndef BSD
  442. X/* all those stupid differences! */
  443. X#define bcopy(src,dest,length)    memcpy((dest),(src),(length))
  444. X#define bzero(block,length)    memset((block),0,(length))
  445. X#endif /* BSD */
  446. X
  447. X#define INFO_FORK    1
  448. X#define RSRC_FORK    2
  449. X#define DATA_FORK    3
  450. X
  451. Xstatic char f_info[I_NAMELEN];
  452. Xstatic char f_data[I_NAMELEN*3];
  453. Xstatic char f_rsrc[I_NAMELEN];
  454. Xstatic char f_text[I_NAMELEN];
  455. Xstatic char f_unix[I_NAMELEN];
  456. Xstatic char f_bin[I_NAMELEN];
  457. Xstatic char f_folder[] = ".foldername";
  458. Xstatic char share_name[256];
  459. X#ifdef APPLESHARE
  460. Xstatic char hex[] = "0123456789abcdef";
  461. X#endif /* APPLESHARE */
  462. X#ifdef AUFS
  463. Xstatic char infodir[] = ".finderinfo";
  464. Xstatic char rsrcdir[] = ".resource";
  465. X#define INFOSZ    sizeof(infodir)
  466. X#define RSRCSZ    sizeof(rsrcdir)
  467. Xstatic char f_info_aufs[I_NAMELEN*3+INFOSZ];
  468. Xstatic char f_rsrc_aufs[I_NAMELEN*3+RSRCSZ];
  469. X#endif /* AUFS */
  470. X#ifdef APPLEDOUBLE
  471. Xstatic char infodir[] = ".AppleDouble";
  472. X#define INFOSZ    sizeof(infodir)
  473. Xstatic char f_info_appledouble[I_NAMELEN*3+INFOSZ];
  474. X#endif /* APPLEDOUBLE */
  475. X
  476. Xstatic int mode = MACB;
  477. Xstatic int mode_restricted = 0;
  478. Xstatic int mode_s_restricted = 0;
  479. Xchar *out_buffer, *out_ptr;
  480. X
  481. Xstatic char init_buffer[128];
  482. Xstatic char *buffer = &(init_buffer[0]);
  483. Xstatic char *rbuffer = NULL, *dbuffer = NULL;
  484. Xstatic char *ptr;
  485. Xstatic unsigned long rsz, dsz, totsize, maxsize;
  486. X
  487. Xvoid define_name(text)
  488. Xchar *text;
  489. X{
  490. X    (void)sprintf(f_info, "%s.info", text);
  491. X    (void)sprintf(f_rsrc, "%s.rsrc", text);
  492. X    (void)sprintf(f_data, "%s.data", text);
  493. X    (void)sprintf(f_text, "%s.text", text);
  494. X    (void)sprintf(f_bin, "%s.bin", text);
  495. X    (void)sprintf(f_unix, "%s", text);
  496. X#ifdef APPLESHARE
  497. X/* Do not do namestuffing here.  We want to base again on the information in
  498. X   the info header, so this is delayed
  499. X*/
  500. X#endif /* APPLESHARE */
  501. X}
  502. X
  503. Xvoid start_info(info, rsize, dsize)
  504. Xchar *info;
  505. Xunsigned long rsize, dsize;
  506. X{
  507. X    int rs, ds;
  508. X
  509. X    rsz = rsize;
  510. X    dsz = dsize;
  511. X    rs = (((rsz + 127) >> 7) << 7);
  512. X    ds = (((dsz + 127) >> 7) << 7);
  513. X    totsize = rs + ds + 128;
  514. X    if(buffer == &(init_buffer[0])) {
  515. X    buffer = (char *)malloc((unsigned)totsize);
  516. X    } else if(maxsize < totsize) {
  517. X    buffer = (char *)realloc(buffer, (unsigned)totsize);
  518. X    }
  519. X    maxsize = totsize;
  520. X    if(buffer == NULL) {
  521. X    (void)fprintf(stderr, "Insufficient memory, aborting\n");
  522. X    exit(1);
  523. X    }
  524. X    dbuffer = buffer + 128;
  525. X    rbuffer = dbuffer + ds;
  526. X    (void)bzero(buffer, (int)totsize);
  527. X    ptr = buffer;
  528. X    (void)bcopy(info, ptr, 128);
  529. X#ifdef AUFS
  530. X/* Now we do filenaming etc. */
  531. X    if(mode == APSH) {
  532. X    aufs_namings();
  533. X    }
  534. X#endif /* AUFS */
  535. X#ifdef APPLEDOUBLE
  536. X/* Now we do filenaming etc. */
  537. X    if(mode == APSH) {
  538. X    appledouble_namings();
  539. X    }
  540. X#endif /* APPLEDOUBLE */
  541. X}
  542. X
  543. Xvoid start_rsrc()
  544. X{
  545. X    out_buffer = out_ptr = rbuffer;
  546. X}
  547. X
  548. Xvoid start_data()
  549. X{
  550. X    out_buffer = out_ptr = dbuffer;
  551. X}
  552. X
  553. Xvoid end_file()
  554. X{
  555. X    FILE *fp;
  556. X    int i, c;
  557. X
  558. X    buffer[I_FLAGOFF] &= (~INITED_MASK);
  559. X    switch(mode) {
  560. X    case FULL:
  561. X    case FORK:
  562. X    fp = fopen(f_info, "w");
  563. X    if(fp == NULL) {
  564. X        perror(f_info);
  565. X        exit(1);
  566. X    }
  567. X    (void)fwrite(buffer, 1, 128, fp);
  568. X    (void)fclose(fp);
  569. X    if(rsz != 0 || mode == FULL) {
  570. X        fp = fopen(f_rsrc, "w");
  571. X        if(fp == NULL) {
  572. X        perror(f_rsrc);
  573. X        exit(1);
  574. X        }
  575. X        (void)fwrite(rbuffer, 1, (int)rsz, fp);
  576. X        (void)fclose(fp);
  577. X    }
  578. X    if(dsz != 0 || mode == FULL) {
  579. X        fp = fopen(f_data, "w");
  580. X        if(fp == NULL) {
  581. X        perror(f_data);
  582. X        exit(1);
  583. X        }
  584. X        (void)fwrite(dbuffer, 1, (int)dsz, fp);
  585. X        (void)fclose(fp);
  586. X    }
  587. X    break;
  588. X    case RSRC:
  589. X    fp = fopen(f_rsrc, "w");
  590. X    if(fp == NULL) {
  591. X        perror(f_rsrc);
  592. X        exit(1);
  593. X    }
  594. X    (void)fwrite(rbuffer, 1, (int)rsz, fp);
  595. X    (void)fclose(fp);
  596. X    break;
  597. X    case DATA:
  598. X    fp = fopen(f_data, "w");
  599. X    if(fp == NULL) {
  600. X        perror(f_data);
  601. X        exit(1);
  602. X    }
  603. X    (void)fwrite(dbuffer, 1, (int)dsz, fp);
  604. X    (void)fclose(fp);
  605. X    break;
  606. X    case TEXT:
  607. X    fp = fopen(f_text, "w");
  608. X    if(fp == NULL) {
  609. X        perror(f_data);
  610. X        exit(1);
  611. X    }
  612. X    for(i = 0; i < dsz; i++) {
  613. X        c = dbuffer[i];
  614. X        if(c == '\012' || c == '\015') {
  615. X        dbuffer[i] = '\027' -c;
  616. X        }
  617. X    }
  618. X    (void)fwrite(dbuffer, 1, (int)dsz, fp);
  619. X    (void)fclose(fp);
  620. X    break;
  621. X    case UNIX:
  622. X    fp = fopen(f_unix, "w");
  623. X    if(fp == NULL) {
  624. X        perror(f_data);
  625. X        exit(1);
  626. X    }
  627. X    for(i = 0; i < dsz; i++) {
  628. X        c = dbuffer[i];
  629. X        if(c == '\012' || c == '\015') {
  630. X        dbuffer[i] = '\027' -c;
  631. X        }
  632. X    }
  633. X    (void)fwrite(dbuffer, 1, (int)dsz, fp);
  634. X    (void)fclose(fp);
  635. X    break;
  636. X    case MACB:
  637. X    fp = fopen(f_bin, "w");
  638. X    if(fp == NULL) {
  639. X        perror(f_bin);
  640. X        exit(1);
  641. X    }
  642. X    if(buffer[I_FLAGOFF + 1] & PROTCT_MASK) {
  643. X        buffer[I_LOCKOFF] = 1;
  644. X    }
  645. X    buffer[I_FLAGOFF + 1] = 0;
  646. X    buffer[I_LOCKOFF + 1] = 0;
  647. X    (void)fwrite(buffer, 1, (int)totsize, fp);
  648. X    (void)fclose(fp);
  649. X    break;
  650. X    case MACS:
  651. X#ifdef SCAN
  652. X    case MACI:
  653. X#endif /* SCAN */
  654. X    if(buffer[I_FLAGOFF + 1] & PROTCT_MASK) {
  655. X        buffer[I_LOCKOFF] = 1;
  656. X    }
  657. X    buffer[I_FLAGOFF + 1] = 0;
  658. X    buffer[I_LOCKOFF + 1] = 0;
  659. X    (void)fwrite(buffer, 1, (int)totsize, stdout);
  660. X    break;
  661. X#ifdef AUFS
  662. X    case APSH:
  663. X    fp = fopen(f_info_aufs, "w");
  664. X    if(fp == NULL) {
  665. X        perror(f_info_aufs);
  666. X        exit(1);
  667. X    }
  668. X    wr_aufs_info(fp);
  669. X    (void) fclose(fp);
  670. X    fp = fopen(f_rsrc_aufs, "w");
  671. X    if(fp == NULL) {
  672. X        perror(f_rsrc_aufs);
  673. X        exit(1);
  674. X    }
  675. X    (void)fwrite(rbuffer, 1, (int)rsz, fp);
  676. X    (void)fclose(fp);
  677. X    fp = fopen(f_data, "w");
  678. X    if(fp == NULL) {
  679. X        perror(f_data);
  680. X        exit(1);
  681. X    }
  682. X    (void)fwrite(dbuffer, 1, (int)dsz, fp);
  683. X    (void)fclose(fp);
  684. X    break;
  685. X#endif /* AUFS */
  686. X#ifdef APPLEDOUBLE
  687. X    case APSH:
  688. X    fp = fopen(f_info_appledouble, "w");
  689. X    if(fp == NULL) {
  690. X        perror(f_info_appledouble);
  691. X        exit(1);
  692. X    }
  693. X    wr_appledouble_info(fp);
  694. X    (void)fwrite(rbuffer, 1, (int)rsz, fp);
  695. X    (void)fclose(fp);
  696. X    fp = fopen(f_data, "w");
  697. X    if(fp == NULL) {
  698. X        perror(f_data);
  699. X        exit(1);
  700. X    }
  701. X    (void)fwrite(dbuffer, 1, (int)dsz, fp);
  702. X    (void)fclose(fp);
  703. X    break;
  704. X#endif /* APPLEDOUBLE */
  705. X    }
  706. X}
  707. X
  708. X#ifdef SCAN
  709. Xvoid do_idf(name, kind)
  710. Xchar *name;
  711. Xint kind;
  712. X{
  713. X    int n;
  714. X
  715. X    if(mode != MACI) {
  716. X    return;
  717. X    }
  718. X    n = strlen(name);
  719. X    (void)bzero(buffer, INFOBYTES);
  720. X    buffer[I_NAMEOFF + 1] = kind;
  721. X    put4(buffer + I_DLENOFF, (unsigned long)n);
  722. X    (void)fwrite(buffer, 1, INFOBYTES, stdout);
  723. X    if(n != 0) {
  724. X    (void)fwrite(name, 1, n, stdout);
  725. X    n = (((n + 127) >> 7) << 7) - n;
  726. X    while(n-- > 0) {
  727. X        (void)fputc(0, stdout);
  728. X    }
  729. X    }
  730. X}
  731. X#endif /* SCAN */
  732. X
  733. Xvoid do_mkdir(name, header)
  734. Xchar *name, *header;
  735. X{
  736. Xstruct stat sbuf;
  737. XFILE *fp;
  738. X#ifdef NOMKDIR
  739. Xchar command[21]; /* Systems without mkdir system call but more than 14
  740. X             char file names?  Ridiculous! */
  741. Xint sysreturn;
  742. X#endif /* MKDIR */
  743. X#ifdef APPLESHARE
  744. Xchar dirinfo[I_NAMELEN*3+INFOSZ+10];
  745. X#endif /* APPLESHARE */
  746. X
  747. X#ifndef SCAN
  748. X    if(mode == MACS) {
  749. X#else /* SCAN */
  750. X    if(mode == MACS || mode == MACI) {
  751. X#endif /* SCAN */
  752. X        header[I_NAMEOFF] |= 0x80;
  753. X    (void)fwrite(header, 1, INFOBYTES, stdout);
  754. X    header[I_NAMEOFF] &= 0x7f;
  755. X    return;
  756. X    }
  757. X#ifdef APPLESHARE
  758. X    if(mode == APSH) {
  759. X    (void)bcopy(header, buffer, INFOBYTES);
  760. X    mk_share_name();
  761. X    } else {
  762. X    (void)strcpy(share_name, name);
  763. X    }
  764. X#else /* APPLESHARE */
  765. X    (void)strcpy(share_name, name);
  766. X#endif /* APPLESHARE */
  767. X    if(stat(share_name, &sbuf) == -1) {  /* directory doesn't exist */
  768. X#ifndef NOMKDIR
  769. X    if(mkdir(share_name, 0777) == -1) {
  770. X        (void)fprintf(stderr, "Can't create subdirectory %s\n", share_name);
  771. X        exit(1);
  772. X    }
  773. X#else /* NOMKDIR */
  774. X    sprintf(command, "mkdir %s", share_name);
  775. X    if((sysreturn = system(command)) != 0) {
  776. X        (void)fprintf(stderr, "Can't create subdirectory %s\n", share_name);
  777. X        exit(sysreturn);
  778. X    }
  779. X#endif /* NOMKDIR */
  780. X    } else {        /* something exists with this name */
  781. X    if((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  782. X        (void)fprintf(stderr, "Directory name %s already in use\n",
  783. X        share_name);
  784. X        exit(1);
  785. X    }
  786. X    }
  787. X    (void)chdir(share_name);
  788. X#ifdef APPLESHARE
  789. X#ifdef AUFS
  790. X    if(mode == APSH) {
  791. X    if(stat(rsrcdir, &sbuf) == -1) {  /* directory doesn't exist */
  792. X        if(mkdir(rsrcdir, 0777) == -1) {
  793. X         (void)fprintf(stderr, "Can't create subdirectory %s\n",
  794. X            rsrcdir);
  795. X         exit(1);
  796. X        }
  797. X    } else {
  798. X        if((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  799. X        (void)fprintf(stderr, "Directory name %s already in use\n",
  800. X            rsrcdir);
  801. X        exit(1);
  802. X        }
  803. X    }
  804. X    if(stat(infodir, &sbuf) == -1) {  /* directory doesn't exist */
  805. X        if(mkdir(infodir, 0777) == -1) {
  806. X         (void)fprintf(stderr, "Can't create subdirectory %s\n",
  807. X            infodir);
  808. X         exit(1);
  809. X        }
  810. X    } else {
  811. X        if((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  812. X        (void)fprintf(stderr, "Directory name %s already in use\n",
  813. X            infodir);
  814. X        exit(1);
  815. X        }
  816. X    }
  817. X    dirinfo[0] = 0;
  818. X    (void)strcat(dirinfo, "../");
  819. X    (void)strcat(dirinfo, infodir);
  820. X    (void)strcat(dirinfo, "/");
  821. X    (void)strcat(dirinfo, share_name);
  822. X    fp = fopen(dirinfo, "w");
  823. X    if(fp == NULL) {
  824. X        perror(dirinfo);
  825. X        exit(1);
  826. X    }
  827. X    wr_aufs_info(fp);
  828. X    (void)fclose(fp);
  829. X    } else {
  830. X    fp = fopen(f_folder, "w");
  831. X    if(fp == NULL) {
  832. X        perror(f_folder);
  833. X        exit(1);
  834. X    }
  835. X        header[I_NAMEOFF] |= 0x80;
  836. X    (void)fwrite(header, 1, INFOBYTES, fp);
  837. X    header[I_NAMEOFF] &= 0x7f;
  838. X    (void)fclose(fp);
  839. X    }
  840. X#endif /* AUFS */
  841. X#ifdef APPLEDOUBLE
  842. X    if(mode == APSH) {
  843. X    if(stat(infodir, &sbuf) == -1) {  /* directory doesn't exist */
  844. X        if(mkdir(infodir, 0777) == -1) {
  845. X         (void)fprintf(stderr, "Can't create subdirectory %s\n",
  846. X            infodir);
  847. X         exit(1);
  848. X        }
  849. X    } else {
  850. X        if((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  851. X        (void)fprintf(stderr, "Directory name %s already in use\n",
  852. X            infodir);
  853. X        exit(1);
  854. X        }
  855. X    }
  856. X    dirinfo[0] = 0;
  857. X    (void)strcat(dirinfo, infodir);
  858. X    (void)strcat(dirinfo, "/.Parent");
  859. X    fp = fopen(dirinfo, "w");
  860. X    if(fp == NULL) {
  861. X        perror(dirinfo);
  862. X        exit(1);
  863. X    }
  864. X    rsz = 0;
  865. X    wr_appledouble_info(fp);
  866. X    (void)fclose(fp);
  867. X    } else {
  868. X    fp = fopen(f_folder, "w");
  869. X    if(fp == NULL) {
  870. X        perror(f_folder);
  871. X        exit(1);
  872. X    }
  873. X    header[I_NAMEOFF] |= 0x80;
  874. X    (void)fwrite(header, 1, INFOBYTES, fp);
  875. X    header[I_NAMEOFF] &= 0x7f;
  876. X    (void)fclose(fp);
  877. X    }
  878. X#endif /* APPLEDOUBLE */
  879. X#else /* APPLESHARE */
  880. X    fp = fopen(f_folder, "w");
  881. X    if(fp == NULL) {
  882. X    perror(f_folder);
  883. X    exit(1);
  884. X    }
  885. X    header[I_NAMEOFF] |= 0x80;
  886. X    (void)fwrite(header, 1, INFOBYTES, fp);
  887. X    header[I_NAMEOFF] &= 0x7f;
  888. X    (void)fclose(fp);
  889. X#endif /* APPLESHARE */
  890. X}
  891. X
  892. Xvoid enddir()
  893. X{
  894. Xchar header[INFOBYTES];
  895. Xint i;
  896. X
  897. X#ifndef SCAN
  898. X    if(mode == MACS) {
  899. X#else /* SCAN */
  900. X    if(mode == MACS || mode == MACI) {
  901. X#endif /* SCAN */
  902. X    for(i = 0; i < INFOBYTES; i++) {
  903. X        header[i] = 0;
  904. X    }
  905. X    header[I_NAMEOFF] = 0x80;
  906. X    (void)fwrite(header, 1, INFOBYTES, stdout);
  907. X    } else {
  908. X    (void)chdir("..");
  909. X    }
  910. X}
  911. X
  912. X#ifdef APPLESHARE
  913. X#ifdef AUFS
  914. Xstatic void check_aufs()
  915. X{
  916. X    /* check for .resource/ and .finderinfo/ */
  917. X    struct stat stbuf;
  918. X    int error = 0;
  919. X
  920. X    if(stat(rsrcdir,&stbuf) < 0) {
  921. X    error ++;
  922. X    } else {
  923. X    if((stbuf.st_mode & S_IFMT) != S_IFDIR) {
  924. X          error ++;
  925. X    }
  926. X    }
  927. X    if(stat(infodir,&stbuf) < 0) {
  928. X    error ++;
  929. X    } else {
  930. X    if((stbuf.st_mode & S_IFMT) != S_IFDIR) {
  931. X          error++;
  932. X    }
  933. X    }
  934. X    if(error) {
  935. X    (void)fprintf(stderr, "Not in an Aufs folder.\n");
  936. X    exit(1);
  937. X    }
  938. X}
  939. X
  940. Xstatic void aufs_namings()
  941. X{
  942. X    mk_share_name();
  943. X    (void)sprintf(f_info_aufs, "%s/%s", infodir, share_name);
  944. X    (void)sprintf(f_rsrc_aufs, "%s/%s", rsrcdir, share_name);
  945. X    (void)sprintf(f_data, "%s", share_name);
  946. X}
  947. X
  948. Xstatic void wr_aufs_info(fp)
  949. XFILE *fp;
  950. X{
  951. X    FileInfo theinfo;
  952. X    int n;
  953. X
  954. X    bzero((char *) &theinfo, sizeof theinfo);
  955. X    theinfo.fi_magic1 = FI_MAGIC1;
  956. X    theinfo.fi_version = FI_VERSION;
  957. X    theinfo.fi_magic = FI_MAGIC;
  958. X    theinfo.fi_bitmap = FI_BM_MACINTOSHFILENAME;
  959. X
  960. X    /* AUFS stores Unix times. */
  961. X#ifdef AUFSPLUS
  962. X    theinfo.fi_datemagic = FI_MAGIC;
  963. X    theinfo.fi_datevalid = FI_CDATE | FI_MDATE;
  964. X    put4(theinfo.fi_ctime, get4(buffer + I_CTIMOFF) - TIMEDIFF);
  965. X    put4(theinfo.fi_mtime, get4(buffer + I_MTIMOFF) - TIMEDIFF);
  966. X    put4(theinfo.fi_utime, (unsigned long)time((time_t *)0));
  967. X#endif /* AUFSPLUS */
  968. X    bcopy(buffer + I_TYPEOFF, theinfo.fi_fndr, 4);
  969. X    bcopy(buffer + I_AUTHOFF, theinfo.fi_fndr + 4, 4);
  970. X    bcopy(buffer + I_FLAGOFF, theinfo.fi_fndr + 8, 2);
  971. X    if((n = buffer[I_NAMEOFF] & 0xff) > F_NAMELEN) {
  972. X    n = F_NAMELEN;
  973. X    }
  974. X    (void)strncpy((char *)theinfo.fi_macfilename, buffer + I_NAMEOFF + 1,n);
  975. X    /* theinfo.fi_macfilename[n] = '\0'; */
  976. X    (void)strcpy((char *)theinfo.fi_comnt,
  977. X    "Converted by Unix utility to Aufs format");
  978. X    theinfo.fi_comln = strlen((char *)theinfo.fi_comnt);
  979. X    (void)fwrite((char *) &theinfo, 1, sizeof theinfo, fp);
  980. X}
  981. X#endif /* AUFS */
  982. X
  983. X#ifdef APPLEDOUBLE
  984. Xstatic void check_appledouble()
  985. X{
  986. X    /* check for .AppleDouble/ */
  987. X    struct stat stbuf;
  988. X    int error = 0;
  989. X
  990. X    if(stat(infodir,&stbuf) < 0) {
  991. X    error ++;
  992. X    } else {
  993. X    if((stbuf.st_mode & S_IFMT) != S_IFDIR) {
  994. X          error++;
  995. X    }
  996. X    }
  997. X    if(error) {
  998. X    (void)fprintf(stderr, "Not in an AppleDouble folder.\n");
  999. X    exit(1);
  1000. X    }
  1001. X}
  1002. X
  1003. Xstatic void appledouble_namings()
  1004. X{
  1005. X    mk_share_name();
  1006. X    (void)sprintf(f_info_appledouble, "%s/%s", infodir, share_name);
  1007. X    (void)sprintf(f_data, "%s", share_name);
  1008. X}
  1009. X
  1010. Xstatic void wr_appledouble_info(fp)
  1011. XFILE *fp;
  1012. X{
  1013. X    FileInfo theinfo;
  1014. X    int n;
  1015. X
  1016. X    bzero((char *) &theinfo, sizeof theinfo);
  1017. X    put4(theinfo.fi_magic, (unsigned long)FI_MAGIC);
  1018. X    put2(theinfo.fi_version, (unsigned long)FI_VERSION);
  1019. X    put4(theinfo.fi_fill5, (unsigned long)FI_FILL5);
  1020. X    put4(theinfo.fi_fill6, (unsigned long)FI_FILL6);
  1021. X    put4(theinfo.fi_hlen, (unsigned long)FI_HLEN);
  1022. X    put4(theinfo.fi_fill7, (unsigned long)FI_FILL7);
  1023. X    put4(theinfo.fi_namptr, (unsigned long)FI_NAMPTR);
  1024. X    put4(theinfo.fi_fill9, (unsigned long)FI_FILL9);
  1025. X    put4(theinfo.fi_commptr, (unsigned long)FI_COMMPTR);
  1026. X    put4(theinfo.fi_fill12, (unsigned long)FI_FILL12);
  1027. X    put4(theinfo.fi_timeptr, (unsigned long)FI_TIMEPTR);
  1028. X    put4(theinfo.fi_timesize, (unsigned long)FI_TIMESIZE);
  1029. X    put4(theinfo.fi_fill15, (unsigned long)FI_FILL15);
  1030. X    put4(theinfo.fi_infoptr, (unsigned long)FI_INFOPTR);
  1031. X    put4(theinfo.fi_infosize, (unsigned long)FI_INFOSIZE);
  1032. X
  1033. X    bcopy(buffer + I_TYPEOFF, theinfo.fi_type, 4);
  1034. X    bcopy(buffer + I_AUTHOFF, theinfo.fi_auth, 4);
  1035. X    bcopy(buffer + I_FLAGOFF, theinfo.fi_finfo, 2);
  1036. X    /* AppleDouble stores Unix times. */
  1037. X    put4(theinfo.fi_ctime, get4(buffer + I_CTIMOFF) - TIMEDIFF);
  1038. X    put4(theinfo.fi_mtime, get4(buffer + I_MTIMOFF) - TIMEDIFF);
  1039. X    if((n = buffer[I_NAMEOFF] & 0xff) > F_NAMELEN) {
  1040. X    n = F_NAMELEN;
  1041. X    }
  1042. X    put4(theinfo.fi_namlen, (unsigned long)n);
  1043. X    (void)strncpy((char *)theinfo.fi_name, buffer + I_NAMEOFF + 1,n);
  1044. X    /* theinfo.fi_macfilename[n] = '\0'; */
  1045. X    (void)strcpy((char *)theinfo.fi_comment,
  1046. X    "Converted by Unix utility to AppleDouble format");
  1047. X    put4(theinfo.fi_commsize, (unsigned long)strlen(theinfo.fi_comment));
  1048. X    put4(theinfo.fi_rsrc, (unsigned long)rsz);
  1049. X    /*  Still TODO */
  1050. X    /*  char    fi_ctime[4];    /* Creation time (Unix time) */
  1051. X    /*  char    fi_mtime[4];    /* Modification time (Unix time) */
  1052. X    (void)fwrite((char *) &theinfo, 1, sizeof theinfo, fp);
  1053. X}
  1054. X#endif /* APPLEDOUBLE */
  1055. X
  1056. Xstatic void mk_share_name()
  1057. X{
  1058. X    int ch;
  1059. X    char *mp, *up;
  1060. X
  1061. X    mp = buffer + 2;
  1062. X    up = &(share_name[0]);
  1063. X    while(ch = *mp++) {
  1064. X    if(isascii(ch) && ! iscntrl(ch) && isprint(ch) && ch != '/') {
  1065. X        *up++ = ch;
  1066. X    } else {
  1067. X        *up++ = ':';
  1068. X        *up++ = hex[(ch >> 4) & 0xf];
  1069. X        *up++ = hex[ch & 0xf];
  1070. X    }
  1071. X    }
  1072. X    *up = 0;
  1073. X}
  1074. X#endif /* APPLESHARE */
  1075. X
  1076. Xint wrfileopt(c)
  1077. Xchar c;
  1078. X{
  1079. X    switch(c) {
  1080. X    case 'b':
  1081. X    mode = MACB;
  1082. X    break;
  1083. X    case 'r':
  1084. X    if(mode_restricted) {
  1085. X        return 0;
  1086. X    }
  1087. X    mode = RSRC;
  1088. X    break;
  1089. X    case 'd':
  1090. X    if(mode_restricted) {
  1091. X        return 0;
  1092. X    }
  1093. X    mode = DATA;
  1094. X    break;
  1095. X    case 'u':
  1096. X    if(mode_restricted) {
  1097. X        return 0;
  1098. X    }
  1099. X    mode = TEXT;
  1100. X    break;
  1101. X    case 'U':
  1102. X    if(mode_restricted) {
  1103. X        return 0;
  1104. X    }
  1105. X    mode = TEXT;
  1106. X    break;
  1107. X    case 'f':
  1108. X    mode = FORK;
  1109. X    break;
  1110. X    case '3':
  1111. X    mode = FULL;
  1112. X    break;
  1113. X    case 's':
  1114. X    if(mode_s_restricted) {
  1115. X        return 0;
  1116. X    }
  1117. X    mode = MACS;
  1118. X    break;
  1119. X#ifdef SCAN
  1120. X    case 'S':
  1121. X    if(mode_s_restricted) {
  1122. X        return 0;
  1123. X    }
  1124. X    mode = MACI;
  1125. X    break;
  1126. X#endif /* SCAN */
  1127. X    case 'a':
  1128. X#ifdef APPLESHARE
  1129. X#ifdef AUFS
  1130. X    check_aufs();
  1131. X    mode = APSH;
  1132. X    break;
  1133. X#endif /* AUFS */
  1134. X#ifdef APPLEDOUBLE
  1135. X    check_appledouble();
  1136. X    mode = APSH;
  1137. X    break;
  1138. X#endif /* APPLEDOUBLE */
  1139. X#else /* APPLESHARE */
  1140. X    (void)fprintf(stderr, "Sorry, Apple-Unix sharing is not supported.\n");
  1141. X    (void)fprintf(stderr, "Recompile or omit -a option.\n");
  1142. X    exit(1);
  1143. X#endif /* APPLESHARE */
  1144. X    default:
  1145. X    return 0;
  1146. X    }
  1147. X    return 1;
  1148. X}
  1149. X
  1150. Xvoid give_wrfileopt()
  1151. X{
  1152. X    (void)fprintf(stderr, "File output options:\n");
  1153. X    (void)fprintf(stderr, "-b:\tMacBinary (default)\n");
  1154. X    if(!mode_s_restricted) {
  1155. X    (void)fprintf(stderr, "-s:\tMacBinary stream to standard output\n");
  1156. X#ifdef SCAN
  1157. X    (void)fprintf(stderr,
  1158. X        "-S:\tas -s but with indication of orignal Unix filename\n");
  1159. X#endif /* SCAN */
  1160. X    }
  1161. X    (void)fprintf(stderr, "-f:\tthree fork mode, skipping empty forks\n");
  1162. X    (void)fprintf(stderr, "-3:\tthe same, writing also empty forks\n");
  1163. X    if(!mode_restricted) {
  1164. X    (void)fprintf(stderr, "-r:\tresource forks only\n");
  1165. X    (void)fprintf(stderr, "-d:\tdata forks only\n");
  1166. X    (void)fprintf(stderr,
  1167. X        "-u:\tdata forks only with Mac -> Unix text file translation\n");
  1168. X    (void)fprintf(stderr,
  1169. X        "-U:\tas -u, but filename will not have an extension\n");
  1170. X    }
  1171. X#ifdef APPLESHARE
  1172. X#ifdef AUFS
  1173. X    (void)fprintf(stderr, "-a:\tAUFS format\n");
  1174. X#endif /* AUFS */
  1175. X#ifdef APPLEDOUBLE
  1176. X    (void)fprintf(stderr, "-a:\tAppleDouble format\n");
  1177. X#endif /* APPLEDOUBLE */
  1178. X#else /* APPLESHARE */
  1179. X    (void)fprintf(stderr, "-a:\tnot supported, needs recompilation\n");
  1180. X#endif /* APPLESHARE */
  1181. X}
  1182. X
  1183. Xvoid set_wrfileopt(restricted)
  1184. X{
  1185. X    mode_restricted = restricted;
  1186. X}
  1187. X
  1188. Xvoid set_s_wrfileopt(restricted)
  1189. X{
  1190. X    mode_s_restricted = restricted;
  1191. X}
  1192. X
  1193. Xchar *get_wrfileopt()
  1194. X{
  1195. X    static char options[20];
  1196. X
  1197. X    (void)strcpy(options, "b");
  1198. X    if(!mode_s_restricted) {
  1199. X    (void)strcat(options, "s");
  1200. X#ifdef SCAN
  1201. X    (void)strcat(options, "S");
  1202. X#endif /* SCAN */
  1203. X    }
  1204. X    (void)strcat(options, "f3");
  1205. X    if(!mode_restricted) {
  1206. X    (void)strcat(options, "rduU");
  1207. X    }
  1208. X    (void)strcat(options, "a");
  1209. X    return options;
  1210. X}
  1211. X
  1212. Xchar *get_mina()
  1213. X{
  1214. X#ifdef APPLESHARE
  1215. X#ifdef AUFS
  1216. X    return ", AUFS supported";
  1217. X#endif /* AUFS */
  1218. X#ifdef APPLEDOUBLE
  1219. X    return ", AppleDouble supported";
  1220. X#endif /* APPLEDOUBLE */
  1221. X#else /* APPLESHARE */
  1222. X    return ", no Apple-Unix sharing supported";
  1223. X#endif /* APPLESHARE */
  1224. X}
  1225. X
  1226. SHAR_EOF
  1227. if test 19424 -ne "`wc -c < 'wrfile.c'`"
  1228. then
  1229.     echo shar: "error transmitting 'wrfile.c'" '(should have been 19424 characters)'
  1230. fi
  1231. fi
  1232. echo shar: "extracting 'fileglob.c'" '(32 characters)'
  1233. if test -f 'fileglob.c'
  1234. then
  1235.     echo shar: "will not over-write existing file 'fileglob.c'"
  1236. else
  1237. sed 's/^X//' << \SHAR_EOF > 'fileglob.c'
  1238. Xint bytes_read, bytes_written;
  1239. X
  1240. SHAR_EOF
  1241. if test 32 -ne "`wc -c < 'fileglob.c'`"
  1242. then
  1243.     echo shar: "error transmitting 'fileglob.c'" '(should have been 32 characters)'
  1244. fi
  1245. fi
  1246. echo shar: "extracting 'aufs.h'" '(1370 characters)'
  1247. if test -f 'aufs.h'
  1248. then
  1249.     echo shar: "will not over-write existing file 'aufs.h'"
  1250. else
  1251. sed 's/^X//' << \SHAR_EOF > 'aufs.h'
  1252. X#define MAXCLEN 199        /* max size of a comment string */
  1253. X#define FINFOLEN 32        /* Finder info is 32 bytes */
  1254. X#define MAXMACFLEN 31        /* max Mac file name length */
  1255. X#define FI_MAGIC1 255
  1256. X#define FI_VERSION 0x10        /* version major 1, minor 0 */
  1257. X                /* if we have more than 8 versions wer're */
  1258. X                /* doiong something wrong anyway */
  1259. X#define FI_MAGIC 0xda
  1260. X#define FI_BM_SHORTFILENAME 0x1    /* is this included? */
  1261. X#define FI_BM_MACINTOSHFILENAME 0x2 /* is this included? */
  1262. X#define FI_MDATE 0x01        /* mtime & utime are valid */
  1263. X#define FI_CDATE 0x02        /* ctime is valid */
  1264. X
  1265. Xtypedef struct {
  1266. X    char    fi_fndr[FINFOLEN];    /* finder info */
  1267. X    short    fi_attr;        /* attributes */
  1268. X    char    fi_magic1;        /* addional magic word check */
  1269. X    char    fi_version;        /* version number */
  1270. X    char    fi_magic;        /* magic word check */
  1271. X    char    fi_bitmap;        /* bitmap of included info */
  1272. X    char    fi_shortfilename[12+1];    /* possible short file name */
  1273. X    char    fi_macfilename[32+1];    /* possible macintosh file name */
  1274. X    char    fi_comln;        /* comment length */
  1275. X    char    fi_comnt[MAXCLEN+1];    /* comment string */
  1276. X#ifdef AUFSPLUS
  1277. X    char    fi_datemagic;        /* sanity check */
  1278. X    char    fi_datevalid;        /* validity flags */
  1279. X    char    fi_ctime[4];        /* mac file create time */
  1280. X    char    fi_mtime[4];        /* mac file modify time */
  1281. X    char    fi_utime[4];        /* (real) time mtime was set */
  1282. X#endif /* AUFSPLUS */
  1283. X} FileInfo;
  1284. X
  1285. SHAR_EOF
  1286. if test 1370 -ne "`wc -c < 'aufs.h'`"
  1287. then
  1288.     echo shar: "error transmitting 'aufs.h'" '(should have been 1370 characters)'
  1289. fi
  1290. fi
  1291. echo shar: "extracting 'appledouble.h'" '(1856 characters)'
  1292. if test -f 'appledouble.h'
  1293. then
  1294.     echo shar: "will not over-write existing file 'appledouble.h'"
  1295. else
  1296. sed 's/^X//' << \SHAR_EOF > 'appledouble.h'
  1297. X#define    FI_MAGIC    333319
  1298. X#define    FI_VERSION    1
  1299. X#define    FI_FILL5    5
  1300. X#define    FI_FILL6    2
  1301. X#define    FI_HLEN        589
  1302. X#define    FI_FILL7    3
  1303. X#define    FI_NAMPTR    86
  1304. X#define    FI_FILL9    4
  1305. X#define    FI_COMMPTR    341
  1306. X#define    FI_FILL12    7
  1307. X#define    FI_TIMEPTR    541
  1308. X#define    FI_TIMESIZE    16
  1309. X#define    FI_FILL15    9
  1310. X#define    FI_INFOPTR    557
  1311. X#define    FI_INFOSIZE    32
  1312. X
  1313. X/* All as char[n] because of possible alignment problems.  But is this needed?
  1314. X   Is this stuff in host order or in client order?  Assuming client order for
  1315. X   the moment.  Will not be a problem on big-endian machines. */
  1316. Xtypedef struct {
  1317. X    char    fi_magic[4];    /* magic header */
  1318. X    char    fi_version[2];    /* version number */
  1319. X    char    fi_fill1[4];    /* = 0, ???? */
  1320. X    char    fi_fill2[4];    /* = 0, ???? */
  1321. X    char    fi_fill3[4];    /* = 0, ???? */
  1322. X    char    fi_fill4[4];    /* = 0, ???? */
  1323. X    char    fi_fill5[4];    /* = 5, ???? */
  1324. X    char    fi_fill6[4];    /* = 2, ???? */
  1325. X    char    fi_hlen[4];    /* = 589, header length */
  1326. X    char    fi_rsrc[4];    /* resource length */
  1327. X    char    fi_fill7[4];    /* = 3, ???? */
  1328. X    char    fi_namptr[4];    /* = 86, filename pointer */
  1329. X    char    fi_namlen[4];    /* Mac filename length */
  1330. X    char    fi_fill9[4];    /* = 4, ???? */
  1331. X    char    fi_commptr[4];    /* = 341, comment pointer */
  1332. X    char    fi_commsize[4];    /* = 0, comment size */
  1333. X    char    fi_fill12[4];    /* = 7, ???? */
  1334. X    char    fi_timeptr[4];    /* = 541, pointer to times */
  1335. X    char    fi_timesize[4];    /* = 16, size of times */
  1336. X    char    fi_fill15[4];    /* = 9, ???? */
  1337. X    char    fi_infoptr[4];    /* = 557, finder info pointer */
  1338. X    char    fi_infosize[4];    /* = 32, finder info size */
  1339. X    char    fi_name[255];    /* Macintosh filename */
  1340. X    char    fi_comment[200];/* = 0, Comment */
  1341. X    char    fi_ctime[4];    /* Creation time (Unix time) */
  1342. X    char    fi_mtime[4];    /* Modification time (Unix time) */
  1343. X    char    fi_fill19[4];    /* = 0, ???? */
  1344. X    char    fi_fill20[4];    /* = 0, ???? */
  1345. X    char    fi_type[4];    /* File type */
  1346. X    char    fi_auth[4];    /* File creator */
  1347. X    char    fi_finfo[24];    /* Finder info */
  1348. X} FileInfo;
  1349. X
  1350. SHAR_EOF
  1351. if test 1856 -ne "`wc -c < 'appledouble.h'`"
  1352. then
  1353.     echo shar: "error transmitting 'appledouble.h'" '(should have been 1856 characters)'
  1354. fi
  1355. fi
  1356. echo shar: "extracting 'rdfile.c'" '(25879 characters)'
  1357. if test -f 'rdfile.c'
  1358. then
  1359.     echo shar: "will not over-write existing file 'rdfile.c'"
  1360. else
  1361. sed 's/^X//' << \SHAR_EOF > 'rdfile.c'
  1362. X#include <stdio.h>
  1363. X#ifdef TYPES_H
  1364. X#include <sys/types.h>
  1365. X#endif /* TYPES_H */
  1366. X#include <sys/stat.h>
  1367. X#include "machdr.h"
  1368. X#include "rdfile.h"
  1369. X#include "rdfileopt.h"
  1370. X#ifndef DIRENT_H
  1371. X#include <sys/dir.h>
  1372. X#define dirstruct direct
  1373. X#else /* DIRENT_H */
  1374. X#include <dirent.h>
  1375. X#define dirstruct dirent
  1376. X#endif /* DIRENT_H */
  1377. X#include "../util/curtime.h"
  1378. X#include "../util/masks.h"
  1379. X#include "../util/util.h"
  1380. X
  1381. X#ifdef AUFSPLUS
  1382. X#define AUFS
  1383. X#endif /* AUFSPLUS */
  1384. X#ifdef AUFS
  1385. X#define APPLESHARE
  1386. X#endif /* AUFS */
  1387. X#ifdef APPLEDOUBLE
  1388. X#define APPLESHARE
  1389. X#endif /* APPLEDOUBLE */
  1390. X
  1391. X#define NOTFOUND    0
  1392. X#define ISFILE        1
  1393. X#define    INFOFILE    2
  1394. X#define INFOEXT        3
  1395. X#define    SKIPFILE    4
  1396. X#define    MACBINARY    5
  1397. X#define    DIRECTORY    6
  1398. X#ifdef APPLESHARE
  1399. X#define    SHAREFILE    7
  1400. X#endif /* APPLESHARE */
  1401. X
  1402. X#define DATA_FORMAT    1
  1403. X#define RSRC_FORMAT    2
  1404. X#define UNIX_FORMAT    3
  1405. X
  1406. Xextern char *malloc();
  1407. Xextern char *realloc();
  1408. Xextern char *strcpy();
  1409. Xextern char *strncpy();
  1410. Xextern char *strcat();
  1411. Xextern void exit();
  1412. X
  1413. Xstatic void check_files();
  1414. Xstatic void read_file();
  1415. Xstatic void enter_dir();
  1416. Xstatic void exit_dir();
  1417. Xstatic int get_stdin_file();
  1418. X
  1419. Xchar file_info[INFOBYTES];
  1420. Xchar *data_fork, *rsrc_fork;
  1421. Xint data_size, rsrc_size;
  1422. Xstatic int max_data_size, max_rsrc_size;
  1423. X
  1424. Xtypedef struct filelist {
  1425. X    int nfiles;
  1426. X    char **files;
  1427. X    int *kind;
  1428. X    struct filelist *previous;
  1429. X    int current;
  1430. X#ifdef APPLESHARE
  1431. X    int shared_dir;
  1432. X#endif /* APPLESHARE */
  1433. X} filelist;
  1434. X
  1435. Xstatic int data_only;
  1436. Xstatic int no_recurse;
  1437. Xstatic int read_stdin;
  1438. Xstatic filelist global_files;
  1439. Xstatic filelist *current_files;
  1440. Xstatic char f_name[] = ".foldername";
  1441. X#ifdef APPLESHARE
  1442. X#ifdef AUFS
  1443. X#include "aufs.h"
  1444. Xstatic char infodir[] = ".finderinfo";
  1445. Xstatic char rsrcdir[] = ".resource";
  1446. Xstatic void read_aufs_info();
  1447. X#endif /* AUFS */
  1448. X#ifdef APPLEDOUBLE
  1449. X#include "appledouble.h"
  1450. Xstatic char infodir[] = ".AppleDouble";
  1451. Xstatic void read_appledouble_info();
  1452. X#endif /* APPLEDOUBLE */
  1453. X#endif /* APPLESHARE */
  1454. Xstatic char filename[255];
  1455. Xstatic int filekind;
  1456. X
  1457. Xvoid setup(argc, argv)
  1458. Xint argc;
  1459. Xchar **argv;
  1460. X{
  1461. X    if(argc == 0) {
  1462. X    read_stdin = 1;
  1463. X    } else {
  1464. X    read_stdin = 0;
  1465. X    global_files.previous = NULL;
  1466. X    global_files.nfiles = argc;
  1467. X    global_files.files = argv;
  1468. X    global_files.current = 0;
  1469. X    current_files = &global_files;
  1470. X    check_files(1);
  1471. X    }
  1472. X}
  1473. X
  1474. Xstatic void check_files(initial)
  1475. Xint initial;
  1476. X{
  1477. X    struct stat stbuf;
  1478. X    int i, j, n;
  1479. X    char filename[255], filename1[255];
  1480. X
  1481. X    /* Check the method to read the file */
  1482. X    current_files->current = 0;
  1483. X    /* Set initially to NOTFOUND or DIRECTORY */
  1484. X    n = current_files->nfiles;
  1485. X    current_files->kind = (int *)malloc((unsigned)n * sizeof(int));
  1486. X    if(current_files->kind == NULL) {
  1487. X    (void)fprintf(stderr, "Insufficient memory\n");
  1488. X    exit(1);
  1489. X    }
  1490. X    for(i = 0; i < n; i++) {
  1491. X    current_files->kind[i] = NOTFOUND;
  1492. X    if(stat(current_files->files[i], &stbuf) >= 0) {
  1493. X        if((stbuf.st_mode & S_IFMT) == S_IFDIR) {
  1494. X        /* We found a directory */
  1495. X        current_files->kind[i] = DIRECTORY;
  1496. X        continue;
  1497. X        }
  1498. X        current_files->kind[i] = ISFILE;
  1499. X    }
  1500. X    }
  1501. X    /* That is enough for data_only mode */
  1502. X    if(data_only) {
  1503. X    return;
  1504. X    }
  1505. X#ifdef APPLESHARE
  1506. X    /* First check whether we are in a folder on a shared volume */
  1507. X    i = 1;
  1508. X#ifdef AUFS
  1509. X    if(stat(rsrcdir,&stbuf) < 0) {
  1510. X    i = 0;
  1511. X    } else {
  1512. X    if((stbuf.st_mode & S_IFMT) != S_IFDIR) {
  1513. X        i = 0;
  1514. X    }
  1515. X    }
  1516. X    if(stat(infodir,&stbuf) < 0) {
  1517. X    i = 0;
  1518. X    } else {
  1519. X    if((stbuf.st_mode & S_IFMT) != S_IFDIR) {
  1520. X        i = 0;
  1521. X    }
  1522. X    }
  1523. X#endif /* AUFS */
  1524. X#ifdef APPLEDOUBLE
  1525. X    if(stat(infodir,&stbuf) < 0) {
  1526. X    i = 0;
  1527. X    } else {
  1528. X    if((stbuf.st_mode & S_IFMT) != S_IFDIR) {
  1529. X        i = 0;
  1530. X    }
  1531. X    }
  1532. X#endif /* APPLEDOUBLE */
  1533. X    current_files->shared_dir = i;
  1534. X#endif /* APPLESHARE */
  1535. X    for(i = 0; i < n; i++) {
  1536. X    if(current_files->kind[i] == NOTFOUND) {
  1537. X        j = 0;
  1538. X    } else if(current_files->kind[i] == ISFILE) {
  1539. X        /* Check whether the file is special */
  1540. X#ifdef APPLESHARE
  1541. X        if(!current_files->shared_dir &&
  1542. X           !strcmp(current_files->files[i], f_name)) {
  1543. X        current_files->kind[i] = SKIPFILE;
  1544. X        continue;
  1545. X        }
  1546. X#else /* APPLESHARE */
  1547. X        if(!strcmp(current_files->files[i], f_name)) {
  1548. X        current_files->kind[i] = SKIPFILE;
  1549. X        continue;
  1550. X        }
  1551. X#endif /* APPLESHARE */
  1552. X        j = 1;
  1553. X    } else if(current_files->kind[i] == SKIPFILE) {
  1554. X        continue;
  1555. X    } else if(!initial) { /* DIRECTORY */
  1556. X        /* Check whether the directory is special */
  1557. X        if(!strcmp(current_files->files[i], ".") ||
  1558. X           !strcmp(current_files->files[i], "..")) {
  1559. X        current_files->kind[i] = SKIPFILE;
  1560. X        }
  1561. X#ifdef APPLESHARE
  1562. X#ifdef AUFS
  1563. X        if(current_files->shared_dir &&
  1564. X           (!strcmp(current_files->files[i], infodir) ||
  1565. X        !strcmp(current_files->files[i], rsrcdir))) {
  1566. X        current_files->kind[i] = SKIPFILE;
  1567. X        }
  1568. X#endif /* AUFS */
  1569. X#ifdef APPLEDOUBLE
  1570. X        if(current_files->shared_dir &&
  1571. X           !strcmp(current_files->files[i], infodir)) {
  1572. X        current_files->kind[i] = SKIPFILE;
  1573. X        }
  1574. X#endif /* APPLEDOUBLE */
  1575. X#endif /* APPLESHARE */
  1576. X        continue;
  1577. X    } else { /* Take all directories from command line! */
  1578. X        continue;
  1579. X    }
  1580. X#ifdef APPLESHARE
  1581. X    /* Check whether file is in shared format */
  1582. X    if(j & current_files->shared_dir) {
  1583. X        j = 0;
  1584. X        filename[0] = 0;
  1585. X        (void)strcat(filename, infodir);
  1586. X        (void)strcat(filename, "/");
  1587. X        (void)strcat(filename, current_files->files[i]);
  1588. X        /* There ought to be an associated file in the info direcory */
  1589. X        if(stat(filename, &stbuf) >= 0) {
  1590. X        current_files->kind[i] = SHAREFILE;
  1591. X        continue;
  1592. X        }
  1593. X    }
  1594. X#endif /* APPLESHARE */
  1595. X    /* If file not found check for the same with .info extension */
  1596. X    if(!j) {
  1597. X        filename[0] = 0;
  1598. X        (void)strcat(filename, current_files->files[i]);
  1599. X        (void)strcat(filename, ".info");
  1600. X        /* Found a .info file, else no such file found */
  1601. X        if(stat(filename, &stbuf) >= 0) {
  1602. X        current_files->kind[i] = INFOEXT;
  1603. X        }
  1604. X        continue;
  1605. X    }
  1606. X    /* Now we found the file.  Check first whether the name ends with
  1607. X       .info */
  1608. X    j = strlen(current_files->files[i]) - 5;
  1609. X    if(!strncmp(current_files->files[i] + j, ".info", 5)) {
  1610. X        /* This is a .info file.  Set as INFOFILE */
  1611. X        current_files->kind[i] = INFOFILE;
  1612. X        /* Now remove from list of files the same with .data or .rsrc
  1613. X           extension */
  1614. X        filename[0] = 0;
  1615. X        (void)strcat(filename, current_files->files[i]);
  1616. X        filename[j] = 0;
  1617. X        (void)strcpy(filename1, filename);
  1618. X        (void)strcat(filename, ".data");
  1619. X        (void)strcat(filename1, ".rsrc");
  1620. X        for(j = i + 1; j < n; j++) {
  1621. X        if(!strcmp(filename, current_files->files[j])) {
  1622. X            /* Associated .data file */
  1623. X            current_files->kind[j] = SKIPFILE;
  1624. X            continue;
  1625. X        }
  1626. X        if(!strcmp(filename1, current_files->files[j])) {
  1627. X            /* Associated .rsrc file */
  1628. X            current_files->kind[j] = SKIPFILE;
  1629. X        }
  1630. X        }
  1631. X        continue;
  1632. X    }
  1633. X    if(!strncmp(current_files->files[i] + j, ".data", 5) ||
  1634. X       !strncmp(current_files->files[i] + j, ".rsrc", 5)) {
  1635. X        /* .data or .rsrc file found.  Check whether there is an
  1636. X           associated .info file in the filelist */
  1637. X        filename[0] = 0;
  1638. X        (void)strcat(filename, current_files->files[i]);
  1639. X        filename[j] = 0;
  1640. X        (void)strcat(filename, ".info");
  1641. X        for(j = i + 1; j < n; j++) {
  1642. X        if(!strcmp(filename, current_files->files[j])) {
  1643. X            /* Found an associated .info file! */
  1644. X            current_files->kind[i] = SKIPFILE;
  1645. X            break;
  1646. X        }
  1647. X        }
  1648. X        if(j < n) {
  1649. X        continue;
  1650. X        }
  1651. X    }
  1652. X    /* Finally nothing special */
  1653. X    current_files->kind[i] = MACBINARY;
  1654. X    }
  1655. X}
  1656. X
  1657. Xint nextfile()
  1658. X{
  1659. X    int i = current_files->current;
  1660. X
  1661. X    if(read_stdin) {
  1662. X    return get_stdin_file();
  1663. X    }
  1664. Xagain:
  1665. X    if(i == current_files->nfiles) {
  1666. X    if(current_files->previous == NULL) {
  1667. X        return ISATEND;
  1668. X    } else {
  1669. X        exit_dir();
  1670. X        current_files->current++;
  1671. X        return ENDDIR;
  1672. X    }
  1673. X    }
  1674. X    filename[0] = 0;
  1675. X    (void)strcat(filename, current_files->files[i]);
  1676. X    filekind = current_files->kind[i];
  1677. X    switch(filekind) {
  1678. X    case DIRECTORY:
  1679. X    if(no_recurse) {
  1680. X        (void)fprintf(stderr, "Directory %s skipped.\n", filename);
  1681. X        i++;
  1682. X        current_files->current = i;
  1683. X        goto again;
  1684. X    }
  1685. X    enter_dir();
  1686. X    return ISDIR;
  1687. X    case SKIPFILE:
  1688. X    i++;
  1689. X    current_files->current = i;
  1690. X    goto again;
  1691. X    case NOTFOUND:
  1692. X    (void)fprintf(stderr, "File %s not found.\n", filename);
  1693. X    exit(1);
  1694. X    default:
  1695. X    read_file();
  1696. X    current_files->current = i + 1;
  1697. X    return ISFILE;
  1698. X    }
  1699. X}
  1700. X
  1701. Xstatic void read_file()
  1702. X{
  1703. X    FILE *fd;
  1704. X    int c, j, lname, skip;
  1705. X    struct stat stbuf;
  1706. X#ifdef APPLESHARE
  1707. X    char filename1[255];
  1708. X#endif /* APPLESHARE */
  1709. X
  1710. X    switch(filekind) {
  1711. X    case ISFILE:
  1712. X    if(stat(filename, &stbuf) < 0) {
  1713. X        (void)fprintf(stderr, "Cannot stat file %s\n", filename);
  1714. X        exit(1);
  1715. X    }
  1716. X    for(j = 0; j < INFOBYTES; j++) {
  1717. X        file_info[j] = 0;
  1718. X    }
  1719. X    (void)strcpy(file_info + I_NAMEOFF + 1, filename);
  1720. X    file_info[I_NAMEOFF] = strlen(filename);
  1721. X    put4(file_info + I_CTIMOFF, (unsigned long)stbuf.st_ctime + TIMEDIFF);
  1722. X    put4(file_info + I_MTIMOFF, (unsigned long)stbuf.st_mtime + TIMEDIFF);
  1723. X    if(data_only == RSRC_FORMAT) {
  1724. X        rsrc_size = stbuf.st_size;
  1725. X        data_size = 0;
  1726. X        if(rsrc_size > max_rsrc_size) {
  1727. X        if(rsrc_fork == NULL) {
  1728. X            rsrc_fork = malloc((unsigned)rsrc_size);
  1729. X        } else {
  1730. X            rsrc_fork = realloc(rsrc_fork, (unsigned)rsrc_size);
  1731. X        }
  1732. X        max_rsrc_size = rsrc_size;
  1733. X        }
  1734. X        (void)strncpy(file_info + I_TYPEOFF, "RSRC", 4);
  1735. X        (void)strncpy(file_info + I_AUTHOFF, "RSED", 4);
  1736. X        put4(file_info + I_RLENOFF, (unsigned long)rsrc_size);
  1737. X        if((fd = fopen(filename, "r")) == NULL) {
  1738. X        (void)fprintf(stderr, "Cannot open file %s\n", filename);
  1739. X        exit(1);
  1740. X        }
  1741. X        if(fread(rsrc_fork, 1, rsrc_size, fd) != rsrc_size) {
  1742. X        (void)fprintf(stderr, "Short file %s\n", filename);
  1743. X        exit(1);
  1744. X        }
  1745. X        (void)fclose(fd);
  1746. X    } else {
  1747. X        data_size = stbuf.st_size;
  1748. X        rsrc_size = 0;
  1749. X        if(data_size > max_data_size) {
  1750. X        if(data_fork == NULL) {
  1751. X            data_fork = malloc((unsigned)data_size);
  1752. X        } else {
  1753. X            data_fork = realloc(data_fork, (unsigned)data_size);
  1754. X        }
  1755. X        max_data_size = data_size;
  1756. X        }
  1757. X        (void)strncpy(file_info + I_TYPEOFF, "TEXT", 4);
  1758. X        (void)strncpy(file_info + I_AUTHOFF, "MACA", 4);
  1759. X        put4(file_info + I_DLENOFF, (unsigned long)data_size);
  1760. X        if((fd = fopen(filename, "r")) == NULL) {
  1761. X        (void)fprintf(stderr, "Cannot open file %s\n", filename);
  1762. X        exit(1);
  1763. X        }
  1764. X        if(fread(data_fork, 1, data_size, fd) != data_size) {
  1765. X        (void)fprintf(stderr, "Short file %s\n", filename);
  1766. X        exit(1);
  1767. X        }
  1768. X        (void)fclose(fd);
  1769. X        if(data_only == UNIX_FORMAT) {
  1770. X        for(j = 0; j < data_size; j++) {
  1771. X            c = data_fork[j];
  1772. X            if(c == '\012' || c == '\015') {
  1773. X            data_fork[j] = '\027' -c;
  1774. X            }
  1775. X        }
  1776. X        }
  1777. X    }
  1778. X    break;
  1779. X    case INFOEXT:
  1780. X    (void)strcat(filename, ".info");
  1781. X    case INFOFILE:
  1782. X    lname = strlen(filename) - 5;
  1783. X    if((fd = fopen(filename, "r")) == NULL) {
  1784. X        (void)fprintf(stderr, "Cannot open file %s\n", filename);
  1785. X        exit(1);
  1786. X    }
  1787. X    if(fread(file_info, 1, INFOBYTES, fd) != INFOBYTES) {
  1788. X        (void)fprintf(stderr, "Cannot read info header %s\n", filename);
  1789. X    }
  1790. X    (void)fclose(fd);
  1791. X    data_size = get4(file_info + I_DLENOFF);
  1792. X    rsrc_size = get4(file_info + I_RLENOFF);
  1793. X    if(data_size > max_data_size) {
  1794. X        if(data_fork == NULL) {
  1795. X        data_fork = malloc((unsigned)data_size);
  1796. X        } else {
  1797. X        data_fork = realloc(data_fork, (unsigned)data_size);
  1798. X        }
  1799. X        max_data_size = data_size;
  1800. X    }
  1801. X    if(rsrc_size > max_rsrc_size) {
  1802. X        if(rsrc_fork == NULL) {
  1803. X        rsrc_fork = malloc((unsigned)rsrc_size);
  1804. X        } else {
  1805. X        rsrc_fork = realloc(rsrc_fork, (unsigned)rsrc_size);
  1806. X        }
  1807. X        max_rsrc_size = rsrc_size;
  1808. X    }
  1809. X    if(data_size != 0) {
  1810. X        filename[lname] = 0;
  1811. X        (void)strcat(filename, ".data");
  1812. X        if((fd = fopen(filename, "r")) == NULL) {
  1813. X        (void)fprintf(stderr, "Cannot open data fork %s\n", filename);
  1814. X        exit(1);
  1815. X        }
  1816. X        if(fread(data_fork, 1, data_size, fd) != data_size) {
  1817. X        (void)fprintf(stderr, "Premature EOF on %s\n", filename);
  1818. X        }
  1819. X        (void)fclose(fd);
  1820. X    }
  1821. X    if(rsrc_size != 0) {
  1822. X        filename[lname] = 0;
  1823. X        (void)strcat(filename, ".rsrc");
  1824. X        if((fd = fopen(filename, "r")) == NULL) {
  1825. X        (void)fprintf(stderr, "Cannot open rsrc fork %s\n", filename);
  1826. X        exit(1);
  1827. X        }
  1828. X        if(fread(rsrc_fork, 1, rsrc_size, fd) != rsrc_size) {
  1829. X        (void)fprintf(stderr, "Premature EOF on %s\n", filename);
  1830. X        }
  1831. X        (void)fclose(fd);
  1832. X    }
  1833. X    break;
  1834. X    case MACBINARY:
  1835. X    if((fd = fopen(filename, "r")) == NULL) {
  1836. X        (void)fprintf(stderr, "Cannot open file %s\n", filename);
  1837. X        exit(1);
  1838. X    }
  1839. X    if(fread(file_info, 1, INFOBYTES, fd) != INFOBYTES) {
  1840. X        (void)fprintf(stderr, "Short file %s\n", filename);
  1841. X        exit(1);
  1842. X    }
  1843. X    if(file_info[0] != 0) {
  1844. X        (void)fprintf(stderr, "File is not MacBinary: %s\n", filename);
  1845. X        exit(1);
  1846. X    }
  1847. X    data_size = get4(file_info + I_DLENOFF);
  1848. X    rsrc_size = get4(file_info + I_RLENOFF);
  1849. X    if(file_info[I_LOCKOFF] & 1) {
  1850. X        file_info[I_FLAGOFF + 1] = PROTCT_MASK;
  1851. X        file_info[I_LOCKOFF] &= ~1;
  1852. X    }
  1853. X    if(data_size != 0) {
  1854. X        if(data_size > max_data_size) {
  1855. X        if(data_fork == NULL) {
  1856. X            data_fork = malloc((unsigned)data_size);
  1857. X        } else {
  1858. X            data_fork = realloc(data_fork, (unsigned)data_size);
  1859. X        }
  1860. X        max_data_size = data_size;
  1861. X        }
  1862. X        if(fread(data_fork, 1, data_size, fd) != data_size) {
  1863. X        (void)fprintf(stderr, "Short file %s\n", filename);
  1864. X        exit(1);
  1865. X        }
  1866. X        skip = (((data_size + 127) >> 7) << 7) - data_size;
  1867. X        for(j = 0; j < skip; j++) {
  1868. X        (void)fgetc(fd);
  1869. X        }
  1870. X    }
  1871. X    if(rsrc_size != 0) {
  1872. X        if(rsrc_size > max_rsrc_size) {
  1873. X        if(rsrc_fork == NULL) {
  1874. X            rsrc_fork = malloc((unsigned)rsrc_size);
  1875. X        } else {
  1876. X            rsrc_fork = realloc(rsrc_fork, (unsigned)rsrc_size);
  1877. X        }
  1878. X        max_rsrc_size = rsrc_size;
  1879. X        }
  1880. X        if(fread(rsrc_fork, 1, rsrc_size, fd) != rsrc_size) {
  1881. X        (void)fprintf(stderr, "Short file %s\n", filename);
  1882. X        exit(1);
  1883. X        }
  1884. X    }
  1885. X    break;
  1886. X#ifdef APPLESHARE
  1887. X    case SHAREFILE:
  1888. X#ifdef AUFS
  1889. X    (void)strcpy(filename1, infodir);
  1890. X    (void)strcat(filename1, "/");
  1891. X    (void)strcat(filename1, filename);
  1892. X    if((fd = fopen(filename1, "r")) == NULL) {
  1893. X        (void)fprintf(stderr, "Cannot open file %s\n", filename1);
  1894. X    }
  1895. X    read_aufs_info(fd);
  1896. X    (void)fclose(fd);
  1897. X    (void)strcpy(filename1, rsrcdir);
  1898. X    (void)strcat(filename1, "/");
  1899. X    (void)strcat(filename1, filename);
  1900. X    if(stat(filename1, &stbuf) >= 0) {
  1901. X        rsrc_size = stbuf.st_size;
  1902. X        put4(file_info + I_RLENOFF, (unsigned long)rsrc_size);
  1903. X        if(rsrc_size > 0) {
  1904. X        if(rsrc_size > max_rsrc_size) {
  1905. X            if(rsrc_fork == NULL) {
  1906. X            rsrc_fork = malloc((unsigned)rsrc_size);
  1907. X            } else {
  1908. X            rsrc_fork = realloc(rsrc_fork, (unsigned)rsrc_size);
  1909. X            }
  1910. X            max_rsrc_size = rsrc_size;
  1911. X        }
  1912. X        if((fd = fopen(filename1, "r")) == NULL) {
  1913. X            (void)fprintf(stderr, "Cannot open file %s\n", filename1);
  1914. X            exit(1);
  1915. X        }
  1916. X        if(fread(rsrc_fork, 1, rsrc_size, fd) != rsrc_size) {
  1917. X            (void)fprintf(stderr, "Short file %s\n", filename1);
  1918. X            exit(1);
  1919. X        }
  1920. X        (void)fclose(fd);
  1921. X        }
  1922. X    }
  1923. X    if(stat(filename, &stbuf) >= 0) {
  1924. X        data_size = stbuf.st_size;
  1925. X        put4(file_info + I_DLENOFF, (unsigned long)data_size);
  1926. X        if(data_size > 0) {
  1927. X        if(data_size > max_data_size) {
  1928. X            if(data_fork == NULL) {
  1929. X            data_fork = malloc((unsigned)data_size);
  1930. X            } else {
  1931. X            data_fork = realloc(data_fork, (unsigned)data_size);
  1932. X            }
  1933. X            max_data_size = data_size;
  1934. X        }
  1935. X        if((fd = fopen(filename, "r")) == NULL) {
  1936. X            (void)fprintf(stderr, "Cannot open file %s\n", filename);
  1937. X            exit(1);
  1938. X        }
  1939. X        if(fread(data_fork, 1, data_size, fd) != data_size) {
  1940. X            (void)fprintf(stderr, "Short file %s\n", filename1);
  1941. X            exit(1);
  1942. X        }
  1943. X        (void)fclose(fd);
  1944. X        }
  1945. X    }
  1946. X#endif /* AUFS */
  1947. X#ifdef APPLEDOUBLE
  1948. X    (void)strcpy(filename1, infodir);
  1949. X    (void)strcat(filename1, "/");
  1950. X    (void)strcat(filename1, filename);
  1951. X    if((fd = fopen(filename1, "r")) == NULL) {
  1952. X        (void)fprintf(stderr, "Cannot open file %s\n", filename1);
  1953. X    }
  1954. X    read_appledouble_info(fd);
  1955. X    rsrc_size = get4(file_info + I_RLENOFF);
  1956. X    if(rsrc_size > 0) {
  1957. X        if(rsrc_size > max_rsrc_size) {
  1958. X        if(rsrc_fork == NULL) {
  1959. X            rsrc_fork = malloc((unsigned)rsrc_size);
  1960. X        } else {
  1961. X            rsrc_fork = realloc(rsrc_fork, (unsigned)rsrc_size);
  1962. X        }
  1963. X        max_rsrc_size = rsrc_size;
  1964. X        }
  1965. X        if(fread(rsrc_fork, 1, rsrc_size, fd) != rsrc_size) {
  1966. X        (void)fprintf(stderr, "Short file %s\n", filename1);
  1967. X        exit(1);
  1968. X        }
  1969. X    }
  1970. X    (void)fclose(fd);
  1971. X    if(stat(filename, &stbuf) >= 0) {
  1972. X        data_size = stbuf.st_size;
  1973. X        put4(file_info + I_DLENOFF, (unsigned long)data_size);
  1974. X        if(data_size > 0) {
  1975. X        if(data_size > max_data_size) {
  1976. X            if(data_fork == NULL) {
  1977. X            data_fork = malloc((unsigned)data_size);
  1978. X            } else {
  1979. X            data_fork = realloc(data_fork, (unsigned)data_size);
  1980. X            }
  1981. X            max_data_size = data_size;
  1982. X        }
  1983. X        if((fd = fopen(filename, "r")) == NULL) {
  1984. X            (void)fprintf(stderr, "Cannot open file %s\n", filename);
  1985. X            exit(1);
  1986. X        }
  1987. X        if(fread(data_fork, 1, data_size, fd) != data_size) {
  1988. X            (void)fprintf(stderr, "Short file %s\n", filename1);
  1989. X            exit(1);
  1990. X        }
  1991. X        (void)fclose(fd);
  1992. X        }
  1993. X    }
  1994. X#endif /* APPLEDOUBLE */
  1995. X    break;
  1996. X#endif /* APPLESHARE */
  1997. X    }
  1998. X}
  1999. X
  2000. Xstatic void enter_dir()
  2001. X{
  2002. X    DIR *directory;
  2003. X    struct dirstruct *curentry;
  2004. X    FILE *fd;
  2005. X    int n, j, namlen;
  2006. X    int listsize, cursize;
  2007. X    char *filetable;
  2008. X    filelist *new_files;
  2009. X#ifdef APPLESHARE
  2010. X    char filename1[255];
  2011. X#endif /* APPLESHARE */
  2012. X
  2013. X    for(j = 0; j < INFOBYTES; j++) {
  2014. X    file_info[j] = 0;
  2015. X    }
  2016. X    (void)strcpy(file_info + I_NAMEOFF + 1, filename);
  2017. X    file_info[I_NAMEOFF] = strlen(filename);
  2018. X    directory = opendir(filename);
  2019. X    if(directory == NULL) {
  2020. X    (void)fprintf(stderr, "Cannot read directory %s\n", filename);
  2021. X    exit(1);
  2022. X    }
  2023. X    listsize = 1024;
  2024. X    filetable = malloc((unsigned)listsize);
  2025. X    cursize = 0;
  2026. X    n = 0;
  2027. X    while((curentry = readdir(directory)) != NULL) {
  2028. X    namlen = strlen(curentry->d_name);
  2029. X    if(namlen + 1 > listsize - cursize) {
  2030. X        listsize += 1024;
  2031. X        filetable = realloc(filetable, (unsigned)listsize);
  2032. X    }
  2033. X    (void)strcpy(filetable + cursize, curentry->d_name);
  2034. X    cursize += (namlen + 1);
  2035. X    n++;
  2036. X    }
  2037. X    filetable = realloc(filetable, (unsigned)cursize);
  2038. X    (void)closedir(directory);
  2039. X    new_files = (filelist *)malloc(sizeof(filelist));
  2040. X    new_files->nfiles = n;
  2041. X    new_files->files = (char **)malloc((unsigned)n * sizeof(char **));
  2042. X    new_files->kind = (int *)malloc((unsigned)n * sizeof(int));
  2043. X    new_files->previous = current_files;
  2044. X    new_files->current = 0;
  2045. X    cursize = 0;
  2046. X    for(j = 0; j < n; j++) {
  2047. X    new_files->files[j] = filetable + cursize;
  2048. X    cursize += (strlen(filetable + cursize) + 1);
  2049. X    }
  2050. X    (void)chdir(filename);
  2051. X#ifdef APPLESHARE
  2052. X    if((fd = fopen(f_name, "r")) != NULL) {
  2053. X    if(fread(file_info, 1, INFOBYTES, fd) != INFOBYTES) {
  2054. X        (void)fprintf(stderr, "File error on %s\n", f_name);
  2055. X        exit(1);
  2056. X    }
  2057. X    file_info[I_NAMEOFF] |= 0x80;
  2058. X    (void)fclose(fd);
  2059. X    } else {
  2060. X#ifdef AUFS
  2061. X    (void)strcpy(filename1, "../");
  2062. X    (void)strcat(filename1, infodir);
  2063. X    (void)strcat(filename1, "/");
  2064. X    (void)strcat(filename1, filename);
  2065. X    if((fd = fopen(filename1, "r")) != NULL) {
  2066. X        read_aufs_info(fd);
  2067. X        (void)fclose(fd);
  2068. X    }
  2069. X#endif /* AUFS */
  2070. X#ifdef APPLEDOUBLE
  2071. X    (void)strcpy(filename1, infodir);
  2072. X    (void)strcat(filename1, "/.Parent");
  2073. X    if((fd = fopen(filename1, "r")) != NULL) {
  2074. X        read_appledouble_info(fd);
  2075. X        (void)fclose(fd);
  2076. X    }
  2077. X#endif /* APPLEDOUBLE */
  2078. X    file_info[I_NAMEOFF] |= 0x80;
  2079. X    }
  2080. X#else /* APPLESHARE */
  2081. X    if((fd = fopen(f_name, "r")) != NULL) {
  2082. X    if(fread(file_info, 1, INFOBYTES, fd) != INFOBYTES) {
  2083. X        (void)fprintf(stderr, "File error on %s\n", f_name);
  2084. X        exit(1);
  2085. X    }
  2086. X    file_info[I_NAMEOFF] |= 0x80;
  2087. X    (void)fclose(fd);
  2088. X    }
  2089. X#endif /* APPLESHARE */
  2090. X    current_files = new_files;
  2091. X    check_files(0);
  2092. X}
  2093. X
  2094. Xstatic void exit_dir()
  2095. X{
  2096. X    filelist *old_files;
  2097. X    int i;
  2098. X
  2099. X    for(i = 0; i < INFOBYTES; i++) {
  2100. X    file_info[i] = 0;
  2101. X    }
  2102. X    file_info[I_NAMEOFF] = 0x80;
  2103. X    old_files = current_files;
  2104. X    /* Do some garbage collection here! */
  2105. X    current_files = current_files->previous;
  2106. X    (void)free(old_files->files[0]);
  2107. X    (void)free((char *)old_files->files);
  2108. X    (void)free((char *)old_files->kind);
  2109. X    (void)free((char *)old_files);
  2110. X    (void)chdir("..");
  2111. X}
  2112. X
  2113. X#ifdef APPLESHARE
  2114. X#ifdef AUFS
  2115. Xstatic void read_aufs_info(fd)
  2116. XFILE *fd;
  2117. X{
  2118. X    FileInfo theinfo;
  2119. X    int i, n;
  2120. X    struct stat stbuf;
  2121. X
  2122. X    for(i = 0; i < INFOBYTES; i++) {
  2123. X    file_info[i] = 0;
  2124. X    }
  2125. X    bzero((char *) &theinfo, sizeof(theinfo));
  2126. X    if(fread((char *)&theinfo, 1, sizeof(theinfo), fd) != sizeof(theinfo)) {
  2127. X    (void)fprintf(stderr, "Short AUFS info header for %s\n", filename);
  2128. X    exit(1);
  2129. X    }
  2130. X    if(theinfo.fi_magic1 & BYTEMASK != FI_MAGIC1 ||
  2131. X       theinfo.fi_version & BYTEMASK != FI_VERSION ||
  2132. X       theinfo.fi_magic & BYTEMASK != FI_MAGIC) {
  2133. X    (void)fprintf(stderr, "Magic number mismatch on %s\n", filename);
  2134. X    exit(1);
  2135. X    }
  2136. X    bcopy(theinfo.fi_fndr, file_info + I_TYPEOFF, 4);
  2137. X    bcopy(theinfo.fi_fndr + 4, file_info + I_AUTHOFF, 4);
  2138. X    bcopy(theinfo.fi_fndr + 8, file_info + I_FLAGOFF, 2);
  2139. X    if(theinfo.fi_bitmap & FI_BM_MACINTOSHFILENAME) {
  2140. X    n = strlen(theinfo.fi_macfilename);
  2141. X    (void)strncpy(file_info + I_NAMEOFF + 1, (char *)theinfo.fi_macfilename,
  2142. X        n);
  2143. X    } else if(theinfo.fi_bitmap & FI_BM_SHORTFILENAME) {
  2144. X    n = strlen(theinfo.fi_shortfilename);
  2145. X    (void)strncpy(file_info + I_NAMEOFF + 1,
  2146. X        (char *)theinfo.fi_shortfilename, n);
  2147. X    } else {
  2148. X    n = strlen(filename);
  2149. X    (void)strncpy(file_info + I_NAMEOFF + 1, filename, n);
  2150. X    }
  2151. X    file_info[I_NAMEOFF] = n;
  2152. X#ifdef AUFSPLUS
  2153. X    if(theinfo.fi_datemagic == FI_MAGIC &&
  2154. X       (theinfo.fi_datevalid & (FI_CDATE | FI_MDATE)) ==
  2155. X        (FI_CDATE | FI_MDATE)) {
  2156. X    put4(file_info + I_CTIMOFF, get4(theinfo.fi_ctime) + TIMEDIFF);
  2157. X    put4(file_info + I_MTIMOFF, get4(theinfo.fi_mtime) + TIMEDIFF);
  2158. X    } else {
  2159. X    if(fstat(fileno(fd), &stbuf) >= 0) {
  2160. X        put4(file_info + I_CTIMOFF,
  2161. X        (unsigned long)stbuf.st_ctime + TIMEDIFF);
  2162. X        put4(file_info + I_MTIMOFF,
  2163. X        (unsigned long)stbuf.st_mtime + TIMEDIFF);
  2164. X    }
  2165. X    }
  2166. X#else /* AUFSPLUS */
  2167. X    if(fstat(fileno(fd), &stbuf) >= 0) {
  2168. X    put4(file_info + I_CTIMOFF, (unsigned long)stbuf.st_ctime + TIMEDIFF);
  2169. X    put4(file_info + I_MTIMOFF, (unsigned long)stbuf.st_mtime + TIMEDIFF);
  2170. X    }
  2171. X#endif /* AUFSPLUS */
  2172. X}
  2173. X#endif /* AUFS */
  2174. X
  2175. X#ifdef APPLEDOUBLE
  2176. X/* This version assumes that the AppleDouble info header is always the same
  2177. X   size and format.  I have not yet seen something that will lead me to
  2178. X   believe different.
  2179. X*/
  2180. Xstatic void read_appledouble_info(fd)
  2181. XFILE *fd;
  2182. X{
  2183. X    FileInfo theinfo;
  2184. X    int i, n;
  2185. X
  2186. X    for(i = 0; i < INFOBYTES; i++) {
  2187. X    file_info[i] = 0;
  2188. X    }
  2189. X    bzero((char *) &theinfo, sizeof(theinfo));
  2190. X    if(fread((char *)&theinfo, 1, sizeof(theinfo), fd) != sizeof(theinfo)) {
  2191. X    (void)fprintf(stderr, "Short AppleDouble info header for %s\n",
  2192. X        filename);
  2193. X    exit(1);
  2194. X    }
  2195. X    if(get4(theinfo.fi_magic) != FI_MAGIC ||
  2196. X       get2(theinfo.fi_version) != FI_VERSION) {
  2197. X    (void)fprintf(stderr, "Magic number mismatch on %s\n", filename);
  2198. X    exit(1);
  2199. X    }
  2200. X    bcopy(theinfo.fi_type, file_info + I_TYPEOFF, 4);
  2201. X    bcopy(theinfo.fi_auth, file_info + I_AUTHOFF, 4);
  2202. X    bcopy(theinfo.fi_finfo, file_info + I_FLAGOFF, 2);
  2203. X    n = get4(theinfo.fi_namlen);
  2204. X    (void)strncpy(file_info + I_NAMEOFF + 1, theinfo.fi_name, n);
  2205. X    file_info[I_NAMEOFF] = n;
  2206. X    put4(file_info + I_CTIMOFF, get4(theinfo.fi_ctime) + TIMEDIFF);
  2207. X    put4(file_info + I_MTIMOFF, get4(theinfo.fi_mtime) + TIMEDIFF);
  2208. X    rsrc_size = get4(theinfo.fi_rsrc);
  2209. X    put4(file_info + I_RLENOFF, (unsigned long)rsrc_size);
  2210. X}
  2211. X#endif /* APPLEDOUBLE */
  2212. X#endif /* APPLESHARE */
  2213. X
  2214. Xstatic int get_stdin_file()
  2215. X{
  2216. X    int i, skip;
  2217. X
  2218. X    i = fgetc(stdin);
  2219. X    if(i == EOF) {
  2220. X    return ISATEND;
  2221. X    }
  2222. X    (void)ungetc(i, stdin);
  2223. X    if(fread(file_info, 1, INFOBYTES, stdin) != INFOBYTES) {
  2224. X    (void)fprintf(stderr, "Short input\n");
  2225. X    exit(1);
  2226. X    }
  2227. X    if(file_info[0] != 0) {
  2228. X    (void)fprintf(stderr, "File is not MacBinary: %s\n", filename);
  2229. X    exit(1);
  2230. X    }
  2231. X    data_size = get4(file_info + I_DLENOFF);
  2232. X    rsrc_size = get4(file_info + I_RLENOFF);
  2233. X    if(file_info[I_LOCKOFF] & 1) {
  2234. X    file_info[I_FLAGOFF + 1] = PROTCT_MASK;
  2235. X    file_info[I_LOCKOFF] &= ~1;
  2236. X    }
  2237. X    if(data_size != 0) {
  2238. X    if(data_size > max_data_size) {
  2239. X        if(data_fork == NULL) {
  2240. X        data_fork = malloc((unsigned)data_size);
  2241. X        } else {
  2242. X        data_fork = realloc(data_fork, (unsigned)data_size);
  2243. X        }
  2244. X        max_data_size = data_size;
  2245. X    }
  2246. X    if(fread(data_fork, 1, data_size, stdin) != data_size) {
  2247. X        (void)fprintf(stderr, "Short input\n");
  2248. X        exit(1);
  2249. X    }
  2250. X    skip = (((data_size + 127) >> 7) << 7) - data_size;
  2251. X    for(i = 0; i < skip; i++) {
  2252. X        (void)fgetc(stdin);
  2253. X    }
  2254. X    }
  2255. X    if(rsrc_size != 0) {
  2256. X    if(rsrc_size > max_rsrc_size) {
  2257. X        if(rsrc_fork == NULL) {
  2258. X        rsrc_fork = malloc((unsigned)rsrc_size);
  2259. X        } else {
  2260. X        rsrc_fork = realloc(rsrc_fork, (unsigned)rsrc_size);
  2261. X        }
  2262. X        max_rsrc_size = rsrc_size;
  2263. X    }
  2264. X    if(fread(rsrc_fork, 1, rsrc_size, stdin) != rsrc_size) {
  2265. X        (void)fprintf(stderr, "Short input\n");
  2266. X        exit(1);
  2267. X    }
  2268. X    skip = (((rsrc_size + 127) >> 7) << 7) - rsrc_size;
  2269. X    for(i = 0; i < skip; i++) {
  2270. X        (void)fgetc(stdin);
  2271. X    }
  2272. X    }
  2273. X    if(file_info[I_NAMEOFF] & 0x80) {
  2274. X    if(file_info[I_NAMEOFF] == 0x80) {
  2275. X        return ENDDIR;
  2276. X    }
  2277. X    return ISDIR;
  2278. X    }
  2279. X    return ISFILE;
  2280. X}
  2281. X
  2282. Xint rdfileopt(c)
  2283. Xchar c;
  2284. X{
  2285. X    switch(c) {
  2286. X    case 'd':
  2287. X    data_only = DATA_FORMAT;
  2288. X    break;
  2289. X    case 'u':
  2290. X    case 'U':
  2291. X    data_only = UNIX_FORMAT;
  2292. X    break;
  2293. X    case 'r':
  2294. X    data_only = RSRC_FORMAT;
  2295. X    break;
  2296. X    default:
  2297. X    return 0;
  2298. X    }
  2299. X    return 1;
  2300. X}
  2301. X
  2302. Xvoid give_rdfileopt()
  2303. X{
  2304. X    (void)fprintf(stderr, "File input options:\n");
  2305. X    (void)fprintf(stderr, "-r:\tread as resource files\n");
  2306. X    (void)fprintf(stderr, "-d:\tread as data files\n");
  2307. X    (void)fprintf(stderr,
  2308. X    "-u:\tread as data files with Unix -> Mac text file translation\n");
  2309. X    (void)fprintf(stderr, "-U:\ta synonym for -u\n");
  2310. X}
  2311. X
  2312. Xvoid set_norecurse()
  2313. X{
  2314. X    no_recurse = 1;
  2315. X}
  2316. X
  2317. Xchar *get_rdfileopt()
  2318. X{
  2319. X    static char options[] = "rduU";
  2320. X
  2321. X    return options;
  2322. X}
  2323. X
  2324. Xchar *get_minb()
  2325. X{
  2326. X#ifdef APPLESHARE
  2327. X#ifdef AUFS
  2328. X    return ", AUFS supported";
  2329. X#endif /* AUFS */
  2330. X#ifdef APPLEDOUBLE
  2331. X    return ", AppleDouble supported";
  2332. X#endif /* APPLEDOUBLE */
  2333. X#else /* APPLESHARE */
  2334. X    return ", no Apple-Unix sharing supported";
  2335. X#endif /* APPLESHARE */
  2336. X}
  2337. X
  2338. SHAR_EOF
  2339. if test 25879 -ne "`wc -c < 'rdfile.c'`"
  2340. then
  2341.     echo shar: "error transmitting 'rdfile.c'" '(should have been 25879 characters)'
  2342. fi
  2343. fi
  2344. echo shar: "extracting 'rdfile.h'" '(247 characters)'
  2345. if test -f 'rdfile.h'
  2346. then
  2347.     echo shar: "will not over-write existing file 'rdfile.h'"
  2348. else
  2349. sed 's/^X//' << \SHAR_EOF > 'rdfile.h'
  2350. X#define    ISATEND        0
  2351. X#define    ISFILE        1
  2352. X#define    ISDIR        2
  2353. X#define    ENDDIR        3
  2354. X
  2355. Xextern char file_info[INFOBYTES];
  2356. Xextern char *data_fork, *rsrc_fork;
  2357. Xextern int data_size, rsrc_size;
  2358. X
  2359. Xextern void setup();
  2360. Xextern int nextfile();
  2361. Xextern char *get_minb();
  2362. X
  2363. SHAR_EOF
  2364. if test 247 -ne "`wc -c < 'rdfile.h'`"
  2365. then
  2366.     echo shar: "error transmitting 'rdfile.h'" '(should have been 247 characters)'
  2367. fi
  2368. fi
  2369. echo shar: "extracting 'rdfileopt.h'" '(114 characters)'
  2370. if test -f 'rdfileopt.h'
  2371. then
  2372.     echo shar: "will not over-write existing file 'rdfileopt.h'"
  2373. else
  2374. sed 's/^X//' << \SHAR_EOF > 'rdfileopt.h'
  2375. Xextern int rdfileopt();
  2376. Xextern void give_rdfileopt();
  2377. Xextern void set_norecurse();
  2378. Xextern char *get_rdfileopt();
  2379. X
  2380. SHAR_EOF
  2381. if test 114 -ne "`wc -c < 'rdfileopt.h'`"
  2382. then
  2383.     echo shar: "error transmitting 'rdfileopt.h'" '(should have been 114 characters)'
  2384. fi
  2385. fi
  2386. echo shar: "extracting 'kind.h'" '(167 characters)'
  2387. if test -f 'kind.h'
  2388. then
  2389.     echo shar: "will not over-write existing file 'kind.h'"
  2390. else
  2391. sed 's/^X//' << \SHAR_EOF > 'kind.h'
  2392. X#ifdef SCAN
  2393. X#define UNIX_NAME    0
  2394. X#define PACK_NAME    1
  2395. X#define ARCH_NAME    2
  2396. X#define    UNKNOWN        16
  2397. X#define    PROTECTED    17
  2398. X#define    ERROR        32
  2399. X#define COPY        33
  2400. X#endif /* SCAN */
  2401. X
  2402. SHAR_EOF
  2403. if test 167 -ne "`wc -c < 'kind.h'`"
  2404. then
  2405.     echo shar: "error transmitting 'kind.h'" '(should have been 167 characters)'
  2406. fi
  2407. fi
  2408. echo shar: "done with directory 'fileio'"
  2409. cd ..
  2410. if test ! -d 'macunpack'
  2411. then
  2412.     echo shar: "creating directory 'macunpack'"
  2413.     mkdir 'macunpack'
  2414. fi
  2415. echo shar: "entering directory 'macunpack'"
  2416. cd 'macunpack'
  2417. echo shar: "extracting 'de_lzah.c'" '(6813 characters)'
  2418. if test -f 'de_lzah.c'
  2419. then
  2420.     echo shar: "will not over-write existing file 'de_lzah.c'"
  2421. else
  2422. sed 's/^X//' << \SHAR_EOF > 'de_lzah.c'
  2423. X#include "macunpack.h"
  2424. X#ifdef SIT
  2425. X#define DELZAH
  2426. X#endif /* SIT */
  2427. X#ifdef LZH
  2428. X#define DELZAH
  2429. X#endif /* LZH */
  2430. X#ifdef DELZAH
  2431. X#include "globals.h"
  2432. X#include "../util/masks.h"
  2433. X#include "../fileio/wrfile.h"
  2434. X
  2435. X/* Note: compare with LZSS decoding in lharc! */
  2436. X
  2437. X#define N    314
  2438. X#define T    (2*N-1)
  2439. X
  2440. X/*    Huffman table used for first 6 bits of offset:
  2441. X    #bits    codes
  2442. X    3    0x000
  2443. X    4    0x040-0x080
  2444. X    5    0x100-0x2c0
  2445. X    6    0x300-0x5c0
  2446. X    7    0x600-0xbc0
  2447. X    8    0xc00-0xfc0
  2448. X*/
  2449. X
  2450. Xstatic unsigned short HuffCode[] = {
  2451. X    0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000,
  2452. X    0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000,
  2453. X    0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000,
  2454. X    0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000,
  2455. X    0x040, 0x040, 0x040, 0x040, 0x040, 0x040, 0x040, 0x040,
  2456. X    0x040, 0x040, 0x040, 0x040, 0x040, 0x040, 0x040, 0x040,
  2457. X    0x080, 0x080, 0x080, 0x080, 0x080, 0x080, 0x080, 0x080,
  2458. X    0x080, 0x080, 0x080, 0x080, 0x080, 0x080, 0x080, 0x080,
  2459. X    0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0,
  2460. X    0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0, 0x0c0,
  2461. X    0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
  2462. X    0x140, 0x140, 0x140, 0x140, 0x140, 0x140, 0x140, 0x140,
  2463. X    0x180, 0x180, 0x180, 0x180, 0x180, 0x180, 0x180, 0x180,
  2464. X    0x1c0, 0x1c0, 0x1c0, 0x1c0, 0x1c0, 0x1c0, 0x1c0, 0x1c0,
  2465. X    0x200, 0x200, 0x200, 0x200, 0x200, 0x200, 0x200, 0x200,
  2466. X    0x240, 0x240, 0x240, 0x240, 0x240, 0x240, 0x240, 0x240,
  2467. X    0x280, 0x280, 0x280, 0x280, 0x280, 0x280, 0x280, 0x280,
  2468. X    0x2c0, 0x2c0, 0x2c0, 0x2c0, 0x2c0, 0x2c0, 0x2c0, 0x2c0,
  2469. X    0x300, 0x300, 0x300, 0x300, 0x340, 0x340, 0x340, 0x340,
  2470. X    0x380, 0x380, 0x380, 0x380, 0x3c0, 0x3c0, 0x3c0, 0x3c0,
  2471. X    0x400, 0x400, 0x400, 0x400, 0x440, 0x440, 0x440, 0x440,
  2472. X    0x480, 0x480, 0x480, 0x480, 0x4c0, 0x4c0, 0x4c0, 0x4c0,
  2473. X    0x500, 0x500, 0x500, 0x500, 0x540, 0x540, 0x540, 0x540,
  2474. X    0x580, 0x580, 0x580, 0x580, 0x5c0, 0x5c0, 0x5c0, 0x5c0,
  2475. X    0x600, 0x600, 0x640, 0x640, 0x680, 0x680, 0x6c0, 0x6c0,
  2476. X    0x700, 0x700, 0x740, 0x740, 0x780, 0x780, 0x7c0, 0x7c0,
  2477. X    0x800, 0x800, 0x840, 0x840, 0x880, 0x880, 0x8c0, 0x8c0,
  2478. X    0x900, 0x900, 0x940, 0x940, 0x980, 0x980, 0x9c0, 0x9c0,
  2479. X    0xa00, 0xa00, 0xa40, 0xa40, 0xa80, 0xa80, 0xac0, 0xac0,
  2480. X    0xb00, 0xb00, 0xb40, 0xb40, 0xb80, 0xb80, 0xbc0, 0xbc0,
  2481. X    0xc00, 0xc40, 0xc80, 0xcc0, 0xd00, 0xd40, 0xd80, 0xdc0,
  2482. X    0xe00, 0xe40, 0xe80, 0xec0, 0xf00, 0xf40, 0xf80, 0xfc0};
  2483. X
  2484. Xstatic short HuffLength[] = {
  2485. X    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  2486. X    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  2487. X    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  2488. X    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  2489. X    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  2490. X    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  2491. X    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  2492. X    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  2493. X    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  2494. X    6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  2495. X    6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  2496. X    6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  2497. X    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  2498. X    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  2499. X    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  2500. X    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8};
  2501. X
  2502. Xunsigned char (*lzah_getbyte)();
  2503. X
  2504. Xstatic void lzah_inithuf();
  2505. Xstatic void lzah_reorder();
  2506. Xstatic void lzah_move();
  2507. Xstatic void lzah_getbit();
  2508. Xstatic void lzah_outchar();
  2509. X
  2510. Xstatic char lzah_buf[4096];
  2511. Xstatic int lzah_bufptr;
  2512. Xstatic int lzah_bitsavail;
  2513. Xstatic int lzah_bits;
  2514. Xstatic int Frequ[1000];
  2515. Xstatic int ForwTree[1000];
  2516. Xstatic int BackTree[1000];
  2517. X
  2518. Xvoid de_lzah(obytes)
  2519. Xunsigned long obytes;
  2520. X{
  2521. X    int i, i1, j, ch, byte, offs, skip;
  2522. X
  2523. X    lzah_inithuf();
  2524. X    lzah_bitsavail = 0;
  2525. X    for(i = 0; i < 4036; i++) {
  2526. X    lzah_buf[i] = ' ';
  2527. X    }
  2528. X    lzah_bufptr = 4036;
  2529. X    while(obytes != 0) {
  2530. X    ch = ForwTree[T - 1];
  2531. X    while(ch < T) {
  2532. X        lzah_getbit();
  2533. X        if(lzah_bits & 0x80) {
  2534. X        ch = ch + 1;
  2535. X        }
  2536. X        ch = ForwTree[ch];
  2537. X    }
  2538. X    ch -= T;
  2539. X    if(Frequ[T - 1] >= 0x8000) {
  2540. X        lzah_reorder();
  2541. X    }
  2542. X
  2543. X    i = BackTree[ch + T];
  2544. X    do {
  2545. X        j = ++Frequ[i];
  2546. X        i1 = i + 1;
  2547. X        if(Frequ[i1] < j) {
  2548. X        while(Frequ[++i1] < j) ;
  2549. X        i1--;
  2550. X        Frequ[i] = Frequ[i1];
  2551. X        Frequ[i1] = j;
  2552. X
  2553. X        j = ForwTree[i];
  2554. X        BackTree[j] = i1;
  2555. X        if(j < T) {
  2556. X            BackTree[j + 1] = i1;
  2557. X        }
  2558. X        ForwTree[i] = ForwTree[i1];
  2559. X        ForwTree[i1] = j;
  2560. X        j = ForwTree[i];
  2561. X        BackTree[j] = i;
  2562. X        if(j < T) {
  2563. X            BackTree[j + 1] = i;
  2564. X        }
  2565. X        i = i1;
  2566. X        }
  2567. X        i = BackTree[i];
  2568. X    } while(i != 0);
  2569. X
  2570. X    if(ch < 256) {
  2571. X        lzah_outchar((char)ch);
  2572. X        obytes--;
  2573. X    } else {
  2574. X        if(lzah_bitsavail != 0) {
  2575. X        byte = (lzah_bits << 1) & BYTEMASK;
  2576. X        lzah_bits = (*lzah_getbyte)() & BYTEMASK;
  2577. X        byte |= (lzah_bits >> lzah_bitsavail);
  2578. X        lzah_bits = lzah_bits << (7 - lzah_bitsavail);
  2579. X        } else {
  2580. X        byte = (*lzah_getbyte)() & BYTEMASK;
  2581. X        }
  2582. X        offs = HuffCode[byte];
  2583. X        skip = HuffLength[byte] - 2;
  2584. X        while(skip-- != 0) {
  2585. X        byte = byte + byte;
  2586. X        lzah_getbit();
  2587. X        if(lzah_bits & 0x80) {
  2588. X            byte++;
  2589. X        }
  2590. X        }
  2591. X        offs |= (byte & 0x3f);
  2592. X        offs = ((lzah_bufptr - offs - 1) & 0xfff);
  2593. X        ch = ch - 253;
  2594. X        while(ch-- > 0) {
  2595. X        lzah_outchar(lzah_buf[offs++ & 0xfff]);
  2596. X        obytes--;
  2597. X        if(obytes == 0) {
  2598. X            break;
  2599. X        }
  2600. X        }
  2601. X    }
  2602. X    }
  2603. X}
  2604. X
  2605. Xstatic void lzah_inithuf()
  2606. X{
  2607. X    int i, j;
  2608. X
  2609. X    for(i = 0; i < N; i++) {
  2610. X    Frequ[i] = 1;
  2611. X    ForwTree[i] = i + T;
  2612. X    BackTree[i + T] = i;
  2613. X    }
  2614. X    for(i = 0, j = N; j < T; i += 2, j++) {
  2615. X    Frequ[j] = Frequ[i] + Frequ[i + 1];
  2616. X    ForwTree[j] = i;
  2617. X    BackTree[i] = j;
  2618. X    BackTree[i + 1] = j;
  2619. X    }
  2620. X    Frequ[T] = 0xffff;
  2621. X    BackTree[T - 1] = 0;
  2622. X}
  2623. X
  2624. Xstatic void lzah_reorder()
  2625. X{
  2626. X    int i, j, k, l;
  2627. X
  2628. X    j = 0;
  2629. X    for(i = 0; i < T; i++) {
  2630. X    if(ForwTree[i] >= T) {
  2631. X        Frequ[j] = ((Frequ[i] + 1) >> 1);
  2632. X        ForwTree[j] = ForwTree[i];
  2633. X        j++;
  2634. X    }
  2635. X    }
  2636. X    for(i = 0, j = N; i < T; i += 2, j++) {
  2637. X    k = i + 1;
  2638. X    l = Frequ[i] + Frequ[k];
  2639. X    Frequ[j] = l;
  2640. X    k = j - 1;
  2641. X    while(l < Frequ[k]) {
  2642. X        k--;
  2643. X    }
  2644. X    k = k + 1;
  2645. X    lzah_move(Frequ + k, Frequ + k + 1, j - k);
  2646. X    Frequ[k] = l;
  2647. X    lzah_move(ForwTree + k, ForwTree + k + 1, j - k);
  2648. X    ForwTree[k] = i;
  2649. X    }
  2650. X    for(i = 0; i < T; i++) {
  2651. X    k = ForwTree[i];
  2652. X    if(k >= T) {
  2653. X        BackTree[k] = i;
  2654. X    } else {
  2655. X        BackTree[k] = i;
  2656. X        BackTree[k + 1] = i;
  2657. X    }
  2658. X    }
  2659. X}
  2660. X
  2661. Xstatic void lzah_move(p, q, n)
  2662. Xint *p, *q, n;
  2663. X{
  2664. X    if(p > q) {
  2665. X    while(n-- > 0) {
  2666. X        *q++ = *p++;
  2667. X    }
  2668. X    } else {
  2669. X    p += n;
  2670. X    q += n;
  2671. X    while(n-- > 0) {
  2672. X        *--q = *--p;
  2673. X    }
  2674. X    }
  2675. X}
  2676. X
  2677. Xstatic void lzah_getbit()
  2678. X{
  2679. X    if(lzah_bitsavail != 0) {
  2680. X    lzah_bits = lzah_bits + lzah_bits;
  2681. X    lzah_bitsavail--;
  2682. X    } else {
  2683. X    lzah_bits = (*lzah_getbyte)() & BYTEMASK;
  2684. X    lzah_bitsavail = 7;
  2685. X    }
  2686. X}
  2687. X
  2688. Xstatic void lzah_outchar(ch)
  2689. Xchar ch;
  2690. X{
  2691. X    *out_ptr++ = ch;
  2692. X    lzah_buf[lzah_bufptr++] = ch;
  2693. X    lzah_bufptr &= 0xfff;
  2694. X}
  2695. X#else /* DELZAH */
  2696. Xint delzah; /* keep lint and some compilers happy */
  2697. X#endif /* DELZAH */
  2698. X
  2699. SHAR_EOF
  2700. if test 6813 -ne "`wc -c < 'de_lzah.c'`"
  2701. then
  2702.     echo shar: "error transmitting 'de_lzah.c'" '(should have been 6813 characters)'
  2703. fi
  2704. fi
  2705. echo shar: "extracting 'pit.c'" '(6442 characters)'
  2706. if test -f 'pit.c'
  2707. then
  2708.     echo shar: "will not over-write existing file 'pit.c'"
  2709. else
  2710. sed 's/^X//' << \SHAR_EOF > 'pit.c'
  2711. X#include "macunpack.h"
  2712. X#ifdef PIT
  2713. X#include "../fileio/wrfile.h"
  2714. X#include "../fileio/fileglob.h"
  2715. X#include "../fileio/kind.h"
  2716. X#include "globals.h"
  2717. X#include "pit.h"
  2718. X#include "../fileio/machdr.h"
  2719. X#include "crc.h"
  2720. X#include "../util/masks.h"
  2721. X#include "../util/util.h"
  2722. X#include "huffman.h"
  2723. X
  2724. Xextern void read_tree();
  2725. Xextern void de_huffman();
  2726. Xextern void set_huffman();
  2727. X
  2728. Xstatic int pit_filehdr();
  2729. Xstatic void pit_wrfile();
  2730. Xstatic void pit_nocomp();
  2731. Xstatic void pit_huffman();
  2732. X
  2733. Xvoid pit()
  2734. X{
  2735. X    struct pit_header filehdr;
  2736. X    char pithdr[4];
  2737. X    int decode, synced, ch;
  2738. X    unsigned long data_crc, crc;
  2739. X
  2740. X    updcrc = binhex_updcrc;
  2741. X    crcinit = binhex_crcinit;
  2742. X    set_huffman(HUFF_BE);
  2743. X    synced = 0;
  2744. X    while(1) {
  2745. X    if(!synced) {
  2746. X        if(fread(pithdr, 1, 4, infp) != 4) {
  2747. X        (void)fprintf(stderr, "Premature EOF\n");
  2748. X#ifdef SCAN
  2749. X        do_error("macunpack: Premature EOF");
  2750. X#endif /* SCAN */
  2751. X        exit(1);
  2752. X        }
  2753. X    }
  2754. X    synced = 0;
  2755. X    if(strncmp(pithdr, "PEnd", 4) == 0) {
  2756. X        break;
  2757. X    }
  2758. X    if(strncmp(pithdr, "PMa", 3) != 0) {
  2759. X        (void)fprintf(stderr, "File contains non PackIt info %.4s\n",
  2760. X            pithdr);
  2761. X#ifdef SCAN
  2762. X        do_error("macunpack: File contains non PackIt info");
  2763. X#endif /* SCAN */
  2764. X        exit(1);
  2765. X    }
  2766. X    switch(pithdr[3]) {
  2767. X    case 'g':
  2768. X    case '4':
  2769. X        break;
  2770. X    case '5':
  2771. X    case '6':
  2772. X        if(pithdr[3] == '6') {
  2773. X        (void)fprintf(stderr, "DES-");
  2774. X        }
  2775. X        (void)fprintf(stderr, "Encrypted file found, trying to sync");
  2776. X        while(!synced) {
  2777. X        ch = getb(infp);
  2778. X        if(ch == 'P') {
  2779. X            pithdr[0] = ch;
  2780. X            pithdr[1] = ch = getb(infp);
  2781. X            if(ch == 'M') {
  2782. X            pithdr[2] = ch = getb(infp);
  2783. X            if(ch == 'a') {
  2784. X                pithdr[3] = ch = getb(infp);
  2785. X                if((ch >= '4' && ch <= '6') || ch == 'g') {
  2786. X                synced = 1;
  2787. X                }
  2788. X            }
  2789. X            } else if(ch == 'E') {
  2790. X            pithdr[2] = ch = getb(infp);
  2791. X            if(ch == 'n') {
  2792. X                pithdr[3] = ch = getb(infp);
  2793. X                if(ch == 'd') {
  2794. X                synced = 1;
  2795. X                }
  2796. X            }
  2797. X            }
  2798. X            if(!synced) {
  2799. X            (void)ungetc(ch, infp);
  2800. X            }
  2801. X        }
  2802. X        }
  2803. X        (void)fprintf(stderr, ", done.\n");
  2804. X#ifdef SCAN
  2805. X        do_idf("", PROTECTED);
  2806. X#endif /* SCAN */
  2807. X        continue;
  2808. X    default:
  2809. X        (void)fprintf(stderr, "File contains non PackIt info %.4s\n",
  2810. X            pithdr);
  2811. X#ifdef SCAN
  2812. X        do_error("macunpack: File contains non PackIt info");
  2813. X#endif /* SCAN */
  2814. X        exit(1);
  2815. X    }
  2816. X    bytes_read = 0;
  2817. X    if(pithdr[3] == '4') {
  2818. X        read_tree();
  2819. X        decode = huffman;
  2820. X    } else {
  2821. X        decode = nocomp;
  2822. X    }
  2823. X    if(pit_filehdr(&filehdr, decode) == -1) {
  2824. X        (void)fprintf(stderr, "Can't read file header\n");
  2825. X#ifdef SCAN
  2826. X        do_error("macunpack: Can't read file header");
  2827. X#endif /* SCAN */
  2828. X        exit(1);
  2829. X    }
  2830. X    bytes_written = filehdr.rlen + filehdr.dlen;
  2831. X    start_info(info, filehdr.rlen, filehdr.dlen);
  2832. X    start_data();
  2833. X    pit_wrfile(filehdr.dlen, decode);
  2834. X    data_crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.dlen);
  2835. X    start_rsrc();
  2836. X    pit_wrfile(filehdr.rlen, decode);
  2837. X    data_crc = (*updcrc)(data_crc, out_buffer, filehdr.rlen);
  2838. X    if(decode == nocomp) {
  2839. X        crc = getb(infp);
  2840. X        crc = (crc << 8) | getb(infp);
  2841. X    } else {
  2842. X        crc = (getihuffbyte() & BYTEMASK) |
  2843. X          ((getihuffbyte() & BYTEMASK) << 8);
  2844. X    }
  2845. X    if(crc != data_crc) {
  2846. X        (void)fprintf(stderr,
  2847. X            "CRC error in file: need 0x%04x, got 0x%04x\n",
  2848. X            (int)crc, (int)data_crc);
  2849. X#ifdef SCAN
  2850. X        do_error("macunpack: CRC error in file");
  2851. X#endif /* SCAN */
  2852. X        exit(1);
  2853. X    }
  2854. X    if(verbose) {
  2855. X        if(decode == nocomp) {
  2856. X        (void)fprintf(stderr, "\tNo compression");
  2857. X        } else {
  2858. X        (void)fprintf(stderr, "\tHuffman compressed (%4.1f%%)",
  2859. X            100.0 * bytes_read / bytes_written);
  2860. X        }
  2861. X    }
  2862. X    if(write_it) {
  2863. X        end_file();
  2864. X    }
  2865. X    if(verbose) {
  2866. X        (void)fprintf(stderr, ".\n");
  2867. X    }
  2868. X    }
  2869. X}
  2870. X
  2871. Xstatic int pit_filehdr(f, compr)
  2872. Xstruct pit_header *f;
  2873. Xint compr;
  2874. X{
  2875. X    register int i;
  2876. X    unsigned long crc;
  2877. X    int n;
  2878. X    char hdr[HDRBYTES];
  2879. X    char ftype[5], fauth[5];
  2880. X
  2881. X    for(i = 0; i < INFOBYTES; i++)
  2882. X    info[i] = '\0';
  2883. X
  2884. X    if(compr == huffman) {
  2885. X    for(i = 0; i < HDRBYTES; i++) {
  2886. X        hdr[i] = getihuffbyte();
  2887. X    }
  2888. X    } else {
  2889. X    if(fread(hdr, 1, HDRBYTES, infp) != HDRBYTES) {
  2890. X        return -1;
  2891. X    }
  2892. X    }
  2893. X    crc = INIT_CRC;
  2894. X    crc = (*updcrc)(crc, hdr, HDRBYTES - 2);
  2895. X
  2896. X    f->hdrCRC = get2(hdr + H_HDRCRC);
  2897. X    if(f->hdrCRC != crc) {
  2898. X    (void)fprintf(stderr,
  2899. X        "\tHeader CRC mismatch: got 0x%04x, need 0x%04x\n",
  2900. X        f->hdrCRC & WORDMASK, (int)crc);
  2901. X    return -1;
  2902. X    }
  2903. X
  2904. X    n = hdr[H_NLENOFF] & BYTEMASK;
  2905. X    if(n > H_NAMELEN) {
  2906. X    n = H_NAMELEN;
  2907. X    }
  2908. X    info[I_NAMEOFF] = n;
  2909. X    copy(info + I_NAMEOFF + 1, hdr + H_NAMEOFF, n);
  2910. X    transname(hdr + H_NAMEOFF, text, n);
  2911. X    text[n] = '\0';
  2912. X
  2913. X    f->rlen = get4(hdr + H_RLENOFF);
  2914. X    f->dlen = get4(hdr + H_DLENOFF);
  2915. X
  2916. X    write_it = 1;
  2917. X    if(list) {
  2918. X    transname(hdr + H_TYPEOFF, ftype, 4);
  2919. X    transname(hdr + H_AUTHOFF, fauth, 4);
  2920. X    do_indent(indent);
  2921. X    (void)fprintf(stderr,
  2922. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  2923. X        text, ftype, fauth, (long)f->dlen, (long)f->rlen);
  2924. X    if(info_only) {
  2925. X        write_it = 0;
  2926. X    }
  2927. X    if(query) {
  2928. X        write_it = do_query();
  2929. X    } else {
  2930. X        (void)fputc('\n', stderr);
  2931. X    }
  2932. X    }
  2933. X
  2934. X
  2935. X    if(write_it) {
  2936. X    define_name(text);
  2937. X
  2938. X    copy(info + I_TYPEOFF, hdr + H_TYPEOFF, 4);
  2939. X    copy(info + I_AUTHOFF, hdr + H_AUTHOFF, 4);
  2940. X    copy(info + I_FLAGOFF, hdr + H_FLAGOFF, 2);
  2941. X    copy(info + I_LOCKOFF, hdr + H_LOCKOFF, 2);
  2942. X    copy(info + I_DLENOFF, hdr + H_DLENOFF, 4);
  2943. X    copy(info + I_RLENOFF, hdr + H_RLENOFF, 4);
  2944. X    copy(info + I_CTIMOFF, hdr + H_CTIMOFF, 4);
  2945. X    copy(info + I_MTIMOFF, hdr + H_MTIMOFF, 4);
  2946. X    }
  2947. X    return 1;
  2948. X}
  2949. X
  2950. Xstatic void pit_wrfile(bytes, type)
  2951. Xunsigned long bytes;
  2952. Xint type;
  2953. X{
  2954. X    if(bytes == 0) {
  2955. X    return;
  2956. X    }
  2957. X    switch(type) {
  2958. X    case nocomp:
  2959. X    pit_nocomp(bytes);
  2960. X    break;
  2961. X    case huffman:
  2962. X    pit_huffman(bytes);
  2963. X    }
  2964. X}
  2965. X
  2966. X/*---------------------------------------------------------------------------*/
  2967. X/*    No compression                                 */
  2968. X/*---------------------------------------------------------------------------*/
  2969. Xstatic void pit_nocomp(ibytes)
  2970. Xunsigned long ibytes;
  2971. X{
  2972. X    int n;
  2973. X
  2974. X    n = fread(out_buffer, 1, (int)ibytes, infp);
  2975. X    if(n != ibytes) {
  2976. X    (void)fprintf(stderr, "Premature EOF\n");
  2977. X#ifdef SCAN
  2978. X    do_error("macunpack: Premature EOF");
  2979. X#endif /* SCAN */
  2980. X    exit(1);
  2981. X    }
  2982. X}
  2983. X
  2984. X/*---------------------------------------------------------------------------*/
  2985. X/*    Huffman compression                             */
  2986. X/*---------------------------------------------------------------------------*/
  2987. Xstatic void pit_huffman(obytes)
  2988. Xunsigned long obytes;
  2989. X{
  2990. X    de_huffman(obytes);
  2991. X}
  2992. X#else /* PIT */
  2993. Xint pit; /* keep lint and some compilers happy */
  2994. X#endif /* PIT */
  2995. X
  2996. SHAR_EOF
  2997. if test 6442 -ne "`wc -c < 'pit.c'`"
  2998. then
  2999.     echo shar: "error transmitting 'pit.c'" '(should have been 6442 characters)'
  3000. fi
  3001. fi
  3002. echo shar: "extracting 'sit.c'" '(19518 characters)'
  3003. if test -f 'sit.c'
  3004. then
  3005.     echo shar: "will not over-write existing file 'sit.c'"
  3006. else
  3007. sed 's/^X//' << \SHAR_EOF > 'sit.c'
  3008. X#include "macunpack.h"
  3009. X#ifdef SIT
  3010. X#include "globals.h"
  3011. X#include "sit.h"
  3012. X#include "crc.h"
  3013. X#include "../util/util.h"
  3014. X#include "../fileio/machdr.h"
  3015. X#include "../fileio/wrfile.h"
  3016. X#include "../fileio/kind.h"
  3017. X#include "../util/masks.h"
  3018. X#include "huffman.h"
  3019. X
  3020. Xextern void de_compress();
  3021. Xextern void core_compress();
  3022. Xextern void de_huffman();
  3023. Xextern void de_huffman_end();
  3024. Xextern void read_tree();
  3025. Xextern void set_huffman();
  3026. Xextern void de_lzah();
  3027. Xextern unsigned char (*lzah_getbyte)();
  3028. X
  3029. Xtypedef struct methodinfo {
  3030. X    char *name;
  3031. X    int number;
  3032. X};
  3033. X
  3034. Xstatic struct methodinfo methods[] = {
  3035. X    {"NoComp",  nocomp},
  3036. X    {"RLE",     rle},
  3037. X    {"LZC",     lzc},
  3038. X    {"Huffman", huffman},
  3039. X    {"LZAH",    lzah},
  3040. X    {"FixHuf",  fixhuf},
  3041. X    {"MW",      mw},
  3042. X};
  3043. Xstatic int sit_nodeptr;
  3044. X
  3045. Xstatic int readsithdr();
  3046. Xstatic int sit_filehdr();
  3047. Xstatic int sit_valid();
  3048. Xstatic int sit_checkm();
  3049. Xstatic char *sit_methname();
  3050. Xstatic void sit_folder();
  3051. Xstatic void sit_unstuff();
  3052. Xstatic void sit_wrfile();
  3053. Xstatic void sit_skip();
  3054. Xstatic void sit_nocomp();
  3055. Xstatic void sit_rle();
  3056. Xstatic void sit_lzc();
  3057. Xstatic void sit_huffman();
  3058. Xstatic void sit_lzah();
  3059. Xstatic unsigned char sit_getbyte();
  3060. Xstatic void sit_fixhuf();
  3061. Xstatic void sit_dosplit();
  3062. Xstatic void sit_mw();
  3063. Xstatic void sit_mw_out();
  3064. Xstatic int sit_mw_in();
  3065. X
  3066. Xstatic short code6[258] = {
  3067. X   1024,  512,  256,  256,  256,  256,  128,  128,
  3068. X    128,  128,  128,  128,  128,  128,  128,  128,
  3069. X    128,  128,   64,   64,   64,   64,   64,   64,
  3070. X     64,   64,   64,   64,   64,   64,   64,   64,
  3071. X     64,   64,   64,   64,   64,   64,   64,   64,
  3072. X     64,   64,   64,   64,   64,   64,   64,   64,
  3073. X     64,   64,   32,   32,   32,   32,   32,   32,
  3074. X     32,   32,   32,   32,   32,   32,   32,   32,
  3075. X     32,   32,   16,   16,   16,   16,   16,   16,
  3076. X     16,   16,   16,   16,   16,   16,   16,   16,
  3077. X     16,   16,   16,   16,   16,   16,   16,   16,
  3078. X     16,   16,   16,   16,   16,   16,   16,   16,
  3079. X     16,   16,   16,   16,   16,   16,   16,   16,
  3080. X     16,   16,   16,   16,   16,   16,   16,   16,
  3081. X     16,   16,   16,    8,    8,   16,   16,    8,
  3082. X      8,    8,    8,    8,    8,    8,    8,    8,
  3083. X      8,    8,    8,    8,    8,    8,    8,    8,
  3084. X      8,    8,    8,    8,    8,    8,    8,    8,
  3085. X      8,    8,    8,    8,    8,    8,    8,    8,
  3086. X      8,    8,    8,    8,    8,    8,    8,    4,
  3087. X      4,    4,    4,    4,    4,    4,    4,    4,
  3088. X      4,    4,    4,    4,    4,    4,    4,    4,
  3089. X      4,    4,    4,    4,    4,    4,    4,    4,
  3090. X      4,    4,    4,    4,    4,    4,    4,    4,
  3091. X      4,    4,    4,    4,    4,    4,    4,    4,
  3092. X      4,    4,    4,    4,    4,    4,    4,    4,
  3093. X      4,    4,    4,    4,    4,    4,    4,    4,
  3094. X      4,    4,    4,    4,    4,    4,    4,    4,
  3095. X      4,    4,    4,    4,    4,    4,    4,    4,
  3096. X      4,    4,    4,    4,    4,    4,    4,    4,
  3097. X      4,    4,    4,    4,    4,    4,    4,    4,
  3098. X      4,    4,    4,    4,    4,    4,    1,    1,
  3099. X      1,    1};
  3100. Xstatic char sit_buffer[32768];
  3101. Xstatic short sit_dict[16385];
  3102. Xstatic unsigned long sit_avail;
  3103. Xstatic int sit_bits_avail;
  3104. X
  3105. Xvoid sit()
  3106. X{
  3107. X    struct sitHdr sithdr;
  3108. X    struct fileHdr filehdr;
  3109. X    int i;
  3110. X
  3111. X    set_huffman(HUFF_BE);
  3112. X    core_compress((char *)NULL);
  3113. X    updcrc = arc_updcrc;
  3114. X    crcinit = arc_crcinit;
  3115. X    if(readsithdr(&sithdr) == 0) {
  3116. X    (void)fprintf(stderr, "Can't read file header\n");
  3117. X#ifdef SCAN
  3118. X    do_error("macunpack: Can't read file header");
  3119. X#endif /* SCAN */
  3120. X    exit(1);
  3121. X    }
  3122. X
  3123. X    for(i = 0; i < sithdr.numFiles; i++) {
  3124. X    if(sit_filehdr(&filehdr, 0) == -1) {
  3125. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  3126. X#ifdef SCAN
  3127. X        do_error("macunpack: Can't read file header");
  3128. X#endif /* SCAN */
  3129. X        exit(1);
  3130. X    }
  3131. X    if(!sit_valid(filehdr)) {
  3132. X        continue;
  3133. X    }
  3134. X    if(filehdr.compRMethod == sfolder) {
  3135. X        sit_folder(text);
  3136. X    } else {
  3137. X        sit_unstuff(filehdr);
  3138. X    }
  3139. X    }
  3140. X}
  3141. X
  3142. Xstatic int readsithdr(s)
  3143. Xstruct sitHdr *s;
  3144. X{
  3145. X    char temp[SITHDRSIZE];
  3146. X
  3147. X    if(fread(temp, 1, SITHDRSIZE, infp) != SITHDRSIZE) {
  3148. X    return 0;
  3149. X    }
  3150. X
  3151. X    if(strncmp(temp + S_SIGNATURE,  "SIT!", 4) != 0 ||
  3152. X    strncmp(temp + S_SIGNATURE2, "rLau", 4) != 0) {
  3153. X    (void)fprintf(stderr, "Not a StuffIt file\n");
  3154. X    return 0;
  3155. X    }
  3156. X
  3157. X    s->numFiles = get2(temp + S_NUMFILES);
  3158. X    s->arcLength = get4(temp + S_ARCLENGTH);
  3159. X
  3160. X    return 1;
  3161. X}
  3162. X
  3163. Xstatic int sit_filehdr(f, skip)
  3164. Xstruct fileHdr *f;
  3165. Xint skip;
  3166. X{
  3167. X    register int i;
  3168. X    unsigned long crc;
  3169. X    int n;
  3170. X    char hdr[FILEHDRSIZE];
  3171. X    char ftype[5], fauth[5];
  3172. X
  3173. X    for(i = 0; i < INFOBYTES; i++) {
  3174. X    info[i] = '\0';
  3175. X    }
  3176. X    if(fread(hdr, 1, FILEHDRSIZE, infp) != FILEHDRSIZE) {
  3177. X    (void)fprintf(stderr, "Can't read file header\n");
  3178. X    return -1;
  3179. X    }
  3180. X    crc = INIT_CRC;
  3181. X    crc = (*updcrc)(crc, hdr, FILEHDRSIZE - 2);
  3182. X
  3183. X    f->hdrCRC = get2(hdr + F_HDRCRC);
  3184. X    if(f->hdrCRC != crc) {
  3185. X    (void)fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n",
  3186. X        f->hdrCRC & WORDMASK, (int)crc);
  3187. X    return -1;
  3188. X    }
  3189. X
  3190. X    n = hdr[F_FNAME] & BYTEMASK;
  3191. X    if(n > F_NAMELEN) {
  3192. X    n = F_NAMELEN;
  3193. X    }
  3194. X    info[I_NAMEOFF] = n;
  3195. X    copy(info + I_NAMEOFF + 1, hdr + F_FNAME + 1, n);
  3196. X    transname(hdr + F_FNAME + 1, text, n);
  3197. X
  3198. X    f->compRMethod = hdr[F_COMPRMETHOD];
  3199. X    f->compDMethod = hdr[F_COMPDMETHOD];
  3200. X    f->rsrcLength = get4(hdr + F_RSRCLENGTH);
  3201. X    f->dataLength = get4(hdr + F_DATALENGTH);
  3202. X    f->compRLength = get4(hdr + F_COMPRLENGTH);
  3203. X    f->compDLength = get4(hdr + F_COMPDLENGTH);
  3204. X    f->rsrcCRC = get2(hdr + F_RSRCCRC);
  3205. X    f->dataCRC = get2(hdr + F_DATACRC);
  3206. X
  3207. X    write_it = !skip;
  3208. X    if(list && !skip) {
  3209. X    if(f->compRMethod != efolder) {
  3210. X        do_indent(indent);
  3211. X    }
  3212. X    if(f->compRMethod == sfolder) {
  3213. X        (void)fprintf(stderr, "folder=\"%s\"", text);
  3214. X    } else if(f->compRMethod != efolder) {
  3215. X        transname(hdr + F_FTYPE, ftype, 4);
  3216. X        transname(hdr + F_CREATOR, fauth, 4);
  3217. X        (void)fprintf(stderr,
  3218. X            "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  3219. X            text, ftype, fauth,
  3220. X            (long)f->dataLength, (long)f->rsrcLength);
  3221. X    }
  3222. X    if(info_only) {
  3223. X        write_it = 0;
  3224. X    }
  3225. X    if(f->compRMethod != efolder) {
  3226. X        if(query) {
  3227. X        write_it = do_query();
  3228. X        } else {
  3229. X        (void)fputc('\n', stderr);
  3230. X        }
  3231. X    }
  3232. X    }
  3233. X
  3234. X    if(write_it) {
  3235. X    define_name(text);
  3236. X
  3237. X    if(f->compRMethod != sfolder) {
  3238. X        copy(info + I_TYPEOFF, hdr + F_FTYPE, 4);
  3239. X        copy(info + I_AUTHOFF, hdr + F_CREATOR, 4);
  3240. X        copy(info + I_FLAGOFF, hdr + F_FNDRFLAGS, 2);
  3241. X        copy(info + I_DLENOFF, hdr + F_DATALENGTH, 4);
  3242. X        copy(info + I_RLENOFF, hdr + F_RSRCLENGTH, 4);
  3243. X        copy(info + I_CTIMOFF, hdr + F_CREATIONDATE, 4);
  3244. X        copy(info + I_MTIMOFF, hdr + F_MODDATE, 4);
  3245. X    }
  3246. X    }
  3247. X    return 1;
  3248. X}
  3249. X
  3250. Xstatic int sit_valid(f)
  3251. Xstruct fileHdr f;
  3252. X{
  3253. X    int fr = f.compRMethod, fd = f.compDMethod;
  3254. X
  3255. X    if(fr == sfolder || fr == efolder) {
  3256. X    return 1;
  3257. X    }
  3258. X    if((fr & prot) || (fd & prot)) {
  3259. X    (void)fprintf(stderr, "\tFile is password protected");
  3260. X#ifdef SCAN
  3261. X    do_idf("", PROTECTED);
  3262. X#endif /* SCAN */
  3263. X    } else if(fr >= prot || fd >= prot) {
  3264. X    (void)fprintf(stderr, "\tUnknown stuffit flags: %x %x", fr, fd);
  3265. X#ifdef SCAN
  3266. X    do_idf("", UNKNOWN);
  3267. X#endif /* SCAN */
  3268. X    } else if(((1 << fr) & sknown) && ((1 << fd) & sknown)) {
  3269. X    if(sit_checkm(fr) && sit_checkm(fd)) {
  3270. X        return 1;
  3271. X    }
  3272. X    if(!sit_checkm(fr)) {
  3273. X        (void)fprintf(stderr, "\tMethod \"%s\" not implemented",
  3274. X            sit_methname(fr));
  3275. X    } else {
  3276. X        (void)fprintf(stderr, "\tMethod \"%s\" not implemented",
  3277. X            sit_methname(fd));
  3278. X    }
  3279. X#ifdef SCAN
  3280. X    do_idf("", UNKNOWN);
  3281. X#endif /* SCAN */
  3282. X    } else {
  3283. X    (void)fprintf(stderr, "\tUnknown compression methods: %x %x", fr, fd);
  3284. X#ifdef SCAN
  3285. X    do_idf("", UNKNOWN);
  3286. X#endif /* SCAN */
  3287. X    }
  3288. X    (void)fprintf(stderr, ", skipping file.\n");
  3289. X    sit_skip(f.compRLength);
  3290. X    sit_skip(f.compDLength);
  3291. X    return 0;
  3292. X}
  3293. X
  3294. Xstatic int sit_checkm(f)
  3295. Xint f;
  3296. X{
  3297. X    switch(f) {
  3298. X    case nocomp:
  3299. X    return 1;
  3300. X    case rle:
  3301. X    return 1;
  3302. X    case lzc:
  3303. X    return 1;
  3304. X    case huffman:
  3305. X    return 1;
  3306. X    case lzah:
  3307. X    return 1;
  3308. X    case fixhuf:
  3309. X    return 1;
  3310. X    case mw:
  3311. X    return 1;
  3312. X    default:
  3313. X    return 0;
  3314. X    }
  3315. X    /* NOTREACHED */
  3316. X}
  3317. X
  3318. Xstatic char *sit_methname(n)
  3319. Xint n;
  3320. X{
  3321. Xint i, nmeths;
  3322. X    nmeths = sizeof(methods) / sizeof(struct methodinfo);
  3323. X    for(i = 0; i < nmeths; i++) {
  3324. X    if(methods[i].number == n) {
  3325. X        return methods[i].name;
  3326. X    }
  3327. X    }
  3328. X    return NULL;
  3329. X}
  3330. X
  3331. Xstatic void sit_folder(name)
  3332. Xchar *name;
  3333. X{
  3334. X    int i, recurse;
  3335. X    char loc_name[64];
  3336. X    struct fileHdr filehdr;
  3337. X
  3338. X    for(i = 0; i < 64; i++) {
  3339. X    loc_name[i] = name[i];
  3340. X    }
  3341. X    if(write_it || info_only) {
  3342. X    if(write_it) {
  3343. X        do_mkdir(text, info);
  3344. X    }
  3345. X    indent++;
  3346. X    while(1) {
  3347. X        if(sit_filehdr(&filehdr, 0) == -1) {
  3348. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  3349. X#ifdef SCAN
  3350. X        do_error("macunpack: Can't read file header");
  3351. X#endif /* SCAN */
  3352. X        exit(1);
  3353. X        }
  3354. X        if(!sit_valid(filehdr)) {
  3355. X        continue;
  3356. X        }
  3357. X        if(filehdr.compRMethod == sfolder) {
  3358. X        sit_folder(text);
  3359. X        } else if(filehdr.compRMethod == efolder) {
  3360. X        break;
  3361. X        } else {
  3362. X        sit_unstuff(filehdr);
  3363. X        }
  3364. X    }
  3365. X    if(write_it) {
  3366. X        enddir();
  3367. X    }
  3368. X    indent--;
  3369. X    if(list) {
  3370. X        do_indent(indent);
  3371. X        (void)fprintf(stderr, "leaving folder \"%s\"\n", loc_name);
  3372. X    }
  3373. X    } else {
  3374. X    recurse = 0;
  3375. X    while(1) {
  3376. X        if(sit_filehdr(&filehdr, 1) == -1) {
  3377. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  3378. X#ifdef SCAN
  3379. X        do_error("macunpack: Can't read file header");
  3380. X#endif /* SCAN */
  3381. X        exit(1);
  3382. X        }
  3383. X        if(filehdr.compRMethod == sfolder) {
  3384. X        recurse++;
  3385. X        } else if(filehdr.compRMethod == efolder) {
  3386. X        recurse--;
  3387. X        if(recurse < 0) {
  3388. X            break;
  3389. X        }
  3390. X        } else {
  3391. X        sit_skip(filehdr.compRLength);
  3392. X        sit_skip(filehdr.compDLength);
  3393. X        }
  3394. X    }
  3395. X    }
  3396. X}
  3397. X
  3398. Xstatic void sit_unstuff(filehdr)
  3399. Xstruct fileHdr filehdr;
  3400. X{
  3401. X    unsigned long crc;
  3402. X
  3403. X    if(write_it) {
  3404. X    start_info(info, filehdr.rsrcLength, filehdr.dataLength);
  3405. X    }
  3406. X    if(verbose) {
  3407. X    (void)fprintf(stderr, "\tRsrc: ");
  3408. X    }
  3409. X    if(write_it) {
  3410. X    start_rsrc();
  3411. X    }
  3412. X    sit_wrfile(filehdr.compRLength, filehdr.rsrcLength, filehdr.compRMethod);
  3413. X    if(write_it) {
  3414. X    crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.rsrcLength);
  3415. X    if(filehdr.rsrcCRC != crc) {
  3416. X        (void)fprintf(stderr,
  3417. X        "CRC error on resource fork: need 0x%04x, got 0x%04x\n",
  3418. X        filehdr.rsrcCRC, (int)crc);
  3419. X#ifdef SCAN
  3420. X        do_error("macunpack: CRC error on resource fork");
  3421. X#endif /* SCAN */
  3422. X        exit(1);
  3423. X    }
  3424. X    }
  3425. X    if(verbose) {
  3426. X    (void)fprintf(stderr, ", Data: ");
  3427. X    }
  3428. X    if(write_it) {
  3429. X    start_data();
  3430. X    }
  3431. X    sit_wrfile(filehdr.compDLength, filehdr.dataLength, filehdr.compDMethod);
  3432. X    if(write_it) {
  3433. X    crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.dataLength);
  3434. X    if(filehdr.dataCRC != crc) {
  3435. X        (void)fprintf(stderr,
  3436. X        "CRC error on data fork: need 0x%04x, got 0x%04x\n",
  3437. X        filehdr.dataCRC, (int)crc);
  3438. X#ifdef SCAN
  3439. X        do_error("macunpack: CRC error on data fork");
  3440. X#endif /* SCAN */
  3441. X        exit(1);
  3442. X    }
  3443. X    end_file();
  3444. X    }
  3445. X    if(verbose) {
  3446. X    (void)fprintf(stderr, ".\n");
  3447. X    }
  3448. X}
  3449. X
  3450. Xstatic void sit_wrfile(ibytes, obytes, type)
  3451. Xunsigned long ibytes, obytes;
  3452. Xunsigned char type;
  3453. X{
  3454. X    if(ibytes == 0) {
  3455. X    if(verbose) {
  3456. X        (void)fprintf(stderr, "empty");
  3457. X    }
  3458. X    return;
  3459. X    }
  3460. X    switch(type) {
  3461. X    case nocomp:        /* no compression */
  3462. X    if(verbose) {
  3463. X        (void)fprintf(stderr, "No compression");
  3464. X    }
  3465. X    if(write_it) {
  3466. X        sit_nocomp(ibytes);
  3467. X    } else {
  3468. X        sit_skip(ibytes);
  3469. X    }
  3470. X    break;
  3471. X    case rle:        /* run length encoding */
  3472. X    if(verbose) {
  3473. X        (void)fprintf(stderr,
  3474. X            "RLE compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  3475. X    }
  3476. X    if(write_it) {
  3477. X        sit_rle(ibytes);
  3478. X    } else {
  3479. X        sit_skip(ibytes);
  3480. X    }
  3481. X    break;
  3482. X    case lzc:            /* LZC compression */
  3483. X    if(verbose) {
  3484. X        (void)fprintf(stderr,
  3485. X            "LZC compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  3486. X    }
  3487. X    if(write_it) {
  3488. X        sit_lzc(ibytes);
  3489. X    } else {
  3490. X        sit_skip(ibytes);
  3491. X    }
  3492. X    break;
  3493. X    case huffman:        /* Huffman compression */
  3494. X    if(verbose) {
  3495. X        (void)fprintf(stderr,
  3496. X            "Huffman compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  3497. X    }
  3498. X    if(write_it) {
  3499. X        sit_huffman(obytes);
  3500. X    } else {
  3501. X        sit_skip(ibytes);
  3502. X    }
  3503. X    break;
  3504. X    case lzah:            /* LZAH compression */
  3505. X    if(verbose) {
  3506. X        (void)fprintf(stderr,
  3507. X            "LZAH compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  3508. X    }
  3509. X    if(write_it) {
  3510. X        sit_lzah(obytes);
  3511. X    } else {
  3512. X        sit_skip(ibytes);
  3513. X    }
  3514. X    break;
  3515. X    case fixhuf:        /* FixHuf compression */
  3516. X    if(verbose) {
  3517. X        (void)fprintf(stderr,
  3518. X            "FixHuf compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  3519. X    }
  3520. X    if(write_it) {
  3521. X        sit_fixhuf(ibytes);
  3522. X    } else {
  3523. X        sit_skip(ibytes);
  3524. X    }
  3525. X    break;
  3526. X    case mw:            /* MW compression */
  3527. X    if(verbose) {
  3528. X        (void)fprintf(stderr,
  3529. X            "MW compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  3530. X    }
  3531. X    if(write_it) {
  3532. X        sit_mw(ibytes);
  3533. X    } else {
  3534. X        sit_skip(ibytes);
  3535. X    }
  3536. X    break;
  3537. X    default:
  3538. X    (void)fprintf(stderr, "Unknown compression method %2x\n", type);
  3539. X#ifdef SCAN
  3540. X    do_idf("", UNKNOWN);
  3541. X#endif /* SCAN */
  3542. X    exit(1);
  3543. X    }
  3544. X}
  3545. X
  3546. X/* skip stuffit file */
  3547. Xstatic void sit_skip(ibytes)
  3548. Xunsigned long ibytes;
  3549. X{
  3550. X    while(ibytes != 0) {
  3551. X    if(getc(infp) == EOF) {
  3552. X        (void)fprintf(stderr, "Premature EOF\n");
  3553. X#ifdef SCAN
  3554. X        do_error("macunpack: Premature EOF");
  3555. X#endif /* SCAN */
  3556. X        exit(1);
  3557. X    }
  3558. X    ibytes--;
  3559. X    }
  3560. X}
  3561. X
  3562. X/*---------------------------------------------------------------------------*/
  3563. X/*    Method 0: No compression                         */
  3564. X/*---------------------------------------------------------------------------*/
  3565. Xstatic void sit_nocomp(ibytes)
  3566. Xunsigned long ibytes;
  3567. X{
  3568. X    int n;
  3569. X
  3570. X    n = fread(out_buffer, 1, (int)ibytes, infp);
  3571. X    if(n != ibytes) {
  3572. X    (void)fprintf(stderr, "Premature EOF\n");
  3573. X#ifdef SCAN
  3574. X    do_error("macunpack: Premature EOF");
  3575. X#endif /* SCAN */
  3576. X    exit(1);
  3577. X    }
  3578. X}
  3579. X
  3580. X/*---------------------------------------------------------------------------*/
  3581. X/*    Method 1: Run length encoding                         */
  3582. X/*---------------------------------------------------------------------------*/
  3583. Xstatic void sit_rle(ibytes)
  3584. Xunsigned long ibytes;
  3585. X{
  3586. X    int ch, lastch, n, i;
  3587. X
  3588. X    while(ibytes != 0) {
  3589. X    ch = getb(infp) & BYTEMASK;
  3590. X    ibytes--;
  3591. X    if(ch == ESC) {
  3592. X        n = (getb(infp) & BYTEMASK) - 1;
  3593. X        ibytes--;
  3594. X        if(n < 0) {
  3595. X        *out_ptr++ = ESC;
  3596. X        lastch = ESC;
  3597. X        n = 1;
  3598. X        } else {
  3599. X        for(i = 0; i < n; i++) {
  3600. X            *out_ptr++ = lastch;
  3601. X        }
  3602. X        }
  3603. X    } else {
  3604. X        *out_ptr++ = ch;
  3605. X        lastch = ch;
  3606. X    }
  3607. X    }
  3608. X}
  3609. X
  3610. X/*---------------------------------------------------------------------------*/
  3611. X/*    Method 2: LZC compressed                         */
  3612. X/*---------------------------------------------------------------------------*/
  3613. Xstatic void sit_lzc(ibytes)
  3614. Xunsigned long ibytes;
  3615. X{
  3616. X    de_compress(ibytes, 14);
  3617. X}
  3618. X
  3619. X/*---------------------------------------------------------------------------*/
  3620. X/*    Method 3: Huffman compressed                         */
  3621. X/*---------------------------------------------------------------------------*/
  3622. Xstatic void sit_huffman(obytes)
  3623. Xunsigned long obytes;
  3624. X{
  3625. X    read_tree();
  3626. X    de_huffman(obytes);
  3627. X}
  3628. X
  3629. X/*---------------------------------------------------------------------------*/
  3630. X/*    Method 5: LZ compression plus adaptive Huffman encoding             */
  3631. X/*---------------------------------------------------------------------------*/
  3632. Xstatic void sit_lzah(obytes)
  3633. Xunsigned long obytes;
  3634. X{
  3635. X    lzah_getbyte = sit_getbyte;
  3636. X    de_lzah(obytes);
  3637. X}
  3638. X
  3639. Xstatic unsigned char sit_getbyte()
  3640. X{
  3641. X    return getb(infp);
  3642. X}
  3643. X
  3644. X/*---------------------------------------------------------------------------*/
  3645. X/*    Method 6: Compression with a fixed Huffman encoding             */
  3646. X/*---------------------------------------------------------------------------*/
  3647. Xstatic void sit_fixhuf(ibytes)
  3648. Xunsigned long ibytes;
  3649. X{
  3650. X    int i, sum, codes, sym, num;
  3651. X    char byte_int[4], byte_short[2];
  3652. X    long size;
  3653. X    int sign;
  3654. X    char *tmp_ptr, *ptr, *end_ptr;
  3655. X
  3656. X    sum = 0;
  3657. X    for(i = 0; i < 258; i++) {
  3658. X    sum += code6[i];
  3659. X    nodelist[i + 1].flag = 1;
  3660. X    }
  3661. X    sit_nodeptr = 258;
  3662. X    sit_dosplit(0, sum, 1, 258);
  3663. X    while(ibytes > 0) {
  3664. X    if(fread(byte_int, 1, 4, infp) != 4) {
  3665. X        (void)fprintf(stderr, "Premature EOF\n");
  3666. X#ifdef SCAN
  3667. X        do_error("Premature EOF");
  3668. X#endif /* SCAN */
  3669. X        exit(1);
  3670. X    }
  3671. X    ibytes -= 4;
  3672. X    size = (long)get4(byte_int);
  3673. X    sign = 0;
  3674. X    if(size < 0) {
  3675. X        size = - size;
  3676. X        sign = 1;
  3677. X    }
  3678. X    size -= 4;
  3679. X    if(sign) {
  3680. X        ibytes -= size;
  3681. X        if(fread(sit_buffer, 1, (int)size, infp) != size) {
  3682. X        (void)fprintf(stderr, "Premature EOF\n");
  3683. X#ifdef SCAN
  3684. X        do_error("Premature EOF");
  3685. X#endif /* SCAN */
  3686. X        exit(1);
  3687. X        }
  3688. X    } else {
  3689. X        ibytes -= size;
  3690. X        if(fread(byte_int, 1, 4, infp) != 4) {
  3691. X        (void)fprintf(stderr, "Premature EOF\n");
  3692. X#ifdef SCAN
  3693. X        do_error("Premature EOF");
  3694. X#endif /* SCAN */
  3695. X        exit(1);
  3696. X        }
  3697. X        size -= 4;
  3698. X        if(fread(byte_short, 1, 2, infp) != 2) {
  3699. X        (void)fprintf(stderr, "Premature EOF\n");
  3700. X#ifdef SCAN
  3701. X        do_error("Premature EOF");
  3702. X#endif /* SCAN */
  3703. X        exit(1);
  3704. X        }
  3705. X        size -= 2;
  3706. X        codes = get2(byte_short);
  3707. X        for(i = 1; i <= codes; i++) {
  3708. X        nodelist[i].byte = getb(infp);
  3709. X        }
  3710. X        size -= codes;
  3711. X        clrhuff();
  3712. X        nodelist[257].byte = 0x100;
  3713. X        nodelist[258].byte = 0x100;
  3714. X        tmp_ptr = out_ptr;
  3715. X        out_ptr = &(sit_buffer[0]);
  3716. X        bytesread = 0;
  3717. X        de_huffman_end(0x100);
  3718. X        while(bytesread < size) {
  3719. X        (void)getb(infp);
  3720. X        bytesread++;
  3721. X        }
  3722. X        size = get4(byte_int);
  3723. X        out_ptr = tmp_ptr;
  3724. X    }
  3725. X    ptr = sit_buffer;
  3726. X    end_ptr = ptr + size;
  3727. X    while(ptr < end_ptr) {
  3728. X        num = *ptr++ & BYTEMASK;
  3729. X        if(num < 0x80) {
  3730. X        while(num-- >= 0) {
  3731. X            *out_ptr++ = *ptr++;
  3732. X        }
  3733. X        } else if(num != 0x80) {
  3734. X        sym = *ptr++;
  3735. X        while(num++ <= 0x100) {
  3736. X            *out_ptr++ = sym;
  3737. X        }
  3738. X        }
  3739. X    }
  3740. X    }
  3741. X}
  3742. X
  3743. Xstatic void sit_dosplit(ptr, sum, low, upp)
  3744. Xint ptr, sum, low, upp;
  3745. X{
  3746. X    int i, locsum;
  3747. X
  3748. X    sum = sum / 2;
  3749. X    locsum = 0;
  3750. X    i = low;
  3751. X    while(locsum < sum) {
  3752. X    locsum += code6[i++ - 1];
  3753. X    }
  3754. X    if(low == i - 1) {
  3755. X    nodelist[ptr].zero = nodelist + low;
  3756. X    } else {
  3757. X    nodelist[ptr].zero = nodelist + ++sit_nodeptr;
  3758. X    sit_dosplit(sit_nodeptr, sum, low, i - 1);
  3759. X    }
  3760. X    if(upp == i) {
  3761. X    nodelist[ptr].one = nodelist + upp;
  3762. X    } else {
  3763. X    nodelist[ptr].one = nodelist + ++sit_nodeptr;
  3764. X    sit_dosplit(sit_nodeptr, sum, i, upp);
  3765. X    }
  3766. X}
  3767. X
  3768. X/*---------------------------------------------------------------------------*/
  3769. X/*    Method 8: Compression with a MW encoding                 */
  3770. X/*---------------------------------------------------------------------------*/
  3771. Xstatic void sit_mw(ibytes)
  3772. Xunsigned long ibytes;
  3773. X{
  3774. X    int ptr;
  3775. X    int max, max1, bits;
  3776. X    char *out_buf;
  3777. X
  3778. X    out_buf = out_buffer;
  3779. X    sit_bits_avail = 0;
  3780. X    sit_avail = 0;
  3781. Xstart_over:
  3782. X    max = 256;
  3783. X    max1 = max + max;
  3784. X    bits = 9;
  3785. X    ptr = sit_mw_in(bits, &ibytes);
  3786. X    if(ptr == max) {
  3787. X    goto start_over;
  3788. X    }
  3789. X    if(ptr > max || ptr < 0) {
  3790. X    out_buffer = out_buf;
  3791. X    return;
  3792. X    }
  3793. X    sit_dict[255] = ptr;
  3794. X    sit_mw_out(ptr);
  3795. X    while(1) {
  3796. X    ptr = sit_mw_in(bits, &ibytes);
  3797. X    if(ptr == max) {
  3798. X        goto start_over;
  3799. X    }
  3800. X    if(ptr > max || ptr < 0) {
  3801. X        out_buffer = out_buf;
  3802. X        return;
  3803. X    }
  3804. X    sit_dict[max++] = ptr;
  3805. X    if(max == max1) {
  3806. X        max1 <<= 1;
  3807. X        bits++;
  3808. X    }
  3809. X    sit_mw_out(ptr);
  3810. X    }
  3811. X}
  3812. X
  3813. Xstatic void sit_mw_out(ptr)
  3814. Xint ptr;
  3815. X{
  3816. X    int stack_ptr;
  3817. X    int stack[16384];
  3818. X
  3819. X    stack_ptr = 1;
  3820. X    stack[0] = ptr;
  3821. X    while(stack_ptr) {
  3822. X    ptr = stack[--stack_ptr];
  3823. X    while(ptr >= 256) {
  3824. X        stack[stack_ptr++] = sit_dict[ptr];
  3825. X        ptr = sit_dict[ptr - 1];
  3826. X    }
  3827. X    *out_buffer++ = ptr;
  3828. X    }
  3829. X}
  3830. X
  3831. Xstatic int sit_mw_in(bits, ibytes)
  3832. Xint bits;
  3833. Xunsigned long *ibytes;
  3834. X{
  3835. X    int res, res1;
  3836. X
  3837. X    while(bits > sit_bits_avail) {
  3838. X    if(*ibytes == 0) {
  3839. X        return -1;
  3840. X    }
  3841. X    (*ibytes)--;
  3842. X    sit_avail += (getb(infp) & BYTEMASK) << sit_bits_avail;
  3843. X    sit_bits_avail += 8;
  3844. X    }
  3845. X    res1 = sit_avail >> bits;
  3846. X    res = sit_avail ^ (res1 << bits);
  3847. X    sit_avail = res1;
  3848. X    sit_bits_avail -= bits;
  3849. X    return res;
  3850. X}
  3851. X
  3852. X#else /* SIT */
  3853. Xint sit; /* keep lint and some compilers happy */
  3854. X#endif /* SIT */
  3855. SHAR_EOF
  3856. if test 19518 -ne "`wc -c < 'sit.c'`"
  3857. then
  3858.     echo shar: "error transmitting 'sit.c'" '(should have been 19518 characters)'
  3859. fi
  3860. fi
  3861. echo shar: "extracting 'lzc.h'" '(599 characters)'
  3862. if test -f 'lzc.h'
  3863. then
  3864.     echo shar: "will not over-write existing file 'lzc.h'"
  3865. else
  3866. sed 's/^X//' << \SHAR_EOF > 'lzc.h'
  3867. X#define HEADERBYTES 48
  3868. X#define MAGIC1    "\253\315\000\060"
  3869. X#define MAGIC2    "\037\235"
  3870. X
  3871. X#define C_DLENOFF    4
  3872. X#define C_DLENOFFC    8
  3873. X#define C_RLENOFF    12
  3874. X#define C_RLENOFFC    16
  3875. X#define C_MTIMOFF    24
  3876. X#define C_CTIMOFF    28
  3877. X#define C_TYPEOFF    32
  3878. X#define C_AUTHOFF    36
  3879. X#define C_FLAGOFF    40
  3880. X
  3881. Xtypedef struct fileHdr {
  3882. X    unsigned long    magic1;
  3883. X    unsigned long    dataLength;
  3884. X    unsigned long    dataCLength;
  3885. X    unsigned long    rsrcLength;
  3886. X    unsigned long    rsrcCLength;
  3887. X    unsigned long    unknown1;
  3888. X    unsigned long    mtime;
  3889. X    unsigned long    ctime;
  3890. X    unsigned long    filetype;
  3891. X    unsigned long    fileauth;
  3892. X    unsigned long    flag1;
  3893. X    unsigned long    flag2;
  3894. X};
  3895. X
  3896. SHAR_EOF
  3897. if test 599 -ne "`wc -c < 'lzc.h'`"
  3898. then
  3899.     echo shar: "error transmitting 'lzc.h'" '(should have been 599 characters)'
  3900. fi
  3901. fi
  3902. echo shar: "extracting 'mcb.c'" '(2591 characters)'
  3903. if test -f 'mcb.c'
  3904. then
  3905.     echo shar: "will not over-write existing file 'mcb.c'"
  3906. else
  3907. sed 's/^X//' << \SHAR_EOF > 'mcb.c'
  3908. X#include "globals.h"
  3909. X#include "../fileio/machdr.h"
  3910. X#include "../fileio/wrfile.h"
  3911. X#include "../util/masks.h"
  3912. X#include "../util/util.h"
  3913. X
  3914. Xstatic int mcb_read;
  3915. X
  3916. Xstatic void mcb_wrfile();
  3917. X
  3918. Xvoid mcb(hdr, rsrcLength, dataLength, toread)
  3919. Xchar *hdr;
  3920. Xunsigned long rsrcLength, dataLength;
  3921. Xint toread;
  3922. X{
  3923. X    register int i;
  3924. X    int n;
  3925. X    char ftype[5], fauth[5];
  3926. X
  3927. X    mcb_read = toread;
  3928. X    for(i = 0; i < INFOBYTES; i++) {
  3929. X    info[i] = hdr[i];
  3930. X    }
  3931. X
  3932. X    n = hdr[I_NAMEOFF] & BYTEMASK;
  3933. X    if(n > F_NAMELEN) {
  3934. X    n = F_NAMELEN;
  3935. X    }
  3936. X    info[I_NAMEOFF] = n;
  3937. X    transname(hdr + I_NAMEOFF + 1, text, n);
  3938. X    if(hdr[I_LOCKOFF] & 1) {
  3939. X    hdr[I_FLAGOFF + 1] = PROTCT_MASK;
  3940. X    hdr[I_LOCKOFF] &= ~1;
  3941. X    }
  3942. X
  3943. X    write_it = 1;
  3944. X    if(list) {
  3945. X    transname(hdr + I_TYPEOFF, ftype, 4);
  3946. X    transname(hdr + I_AUTHOFF, fauth, 4);
  3947. X    do_indent(indent);
  3948. X    (void)fprintf(stderr,
  3949. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  3950. X        text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  3951. X    if(info_only) {
  3952. X        write_it = 0;
  3953. X    }
  3954. X    if(query) {
  3955. X        write_it = do_query();
  3956. X    } else {
  3957. X        (void)fputc('\n', stderr);
  3958. X    }
  3959. X    }
  3960. X
  3961. X    if(write_it) {
  3962. X    define_name(text);
  3963. X    }
  3964. X    if(write_it) {
  3965. X    start_info(info, rsrcLength, dataLength);
  3966. X    }
  3967. X    if(verbose) {
  3968. X    (void)fprintf(stderr, "\tData: ");
  3969. X    }
  3970. X    if(write_it) {
  3971. X    start_data();
  3972. X    }
  3973. X    mcb_wrfile(dataLength);
  3974. X    if(verbose) {
  3975. X    (void)fprintf(stderr, ", Rsrc: ");
  3976. X    }
  3977. X    if(write_it) {
  3978. X    start_rsrc();
  3979. X    }
  3980. X    mcb_wrfile(rsrcLength);
  3981. X    if(write_it) {
  3982. X    end_file();
  3983. X    }
  3984. X    if(verbose) {
  3985. X    (void)fprintf(stderr, ".\n");
  3986. X    }
  3987. X}
  3988. X
  3989. Xstatic void mcb_wrfile(ibytes)
  3990. Xunsigned long ibytes;
  3991. X{
  3992. X    int n;
  3993. X
  3994. X    if(ibytes == 0) {
  3995. X    if(verbose) {
  3996. X        (void)fprintf(stderr, "empty");
  3997. X    }
  3998. X    return;
  3999. X    }
  4000. X    if(verbose) {
  4001. X    (void)fprintf(stderr, "No compression");
  4002. X    }
  4003. X    if(write_it) {
  4004. X    n = fread(out_buffer, 1, (int)ibytes, infp);
  4005. X    if(n != ibytes) {
  4006. X        (void)fprintf(stderr, "Premature EOF\n");
  4007. X#ifdef SCAN
  4008. X        do_error("macunpack: Premature EOF");
  4009. X#endif /* SCAN */
  4010. X        exit(1);
  4011. X    }
  4012. X    mcb_read -= n;
  4013. X    n = ((n + 127) / 128) * 128 - n;
  4014. X    if(n > mcb_read) {
  4015. X        n = mcb_read;
  4016. X    }
  4017. X    mcb_read -= n;
  4018. X    while(n-- > 0) {
  4019. X        if(getc(infp) == EOF) {
  4020. X        (void)fprintf(stderr, "Premature EOF\n");
  4021. X#ifdef SCAN
  4022. X        do_error("macunpack: Premature EOF");
  4023. X#endif /* SCAN */
  4024. X        exit(1);
  4025. X        }
  4026. X    }
  4027. X    } else {
  4028. X    n = ((ibytes + 127) / 128) * 128;
  4029. X    if(n > mcb_read) {
  4030. X        n = mcb_read;
  4031. X    }
  4032. X    mcb_read -= n;
  4033. X    while(n-- > 0) {
  4034. X        if(getc(infp) == EOF) {
  4035. X        (void)fprintf(stderr, "Premature EOF\n");
  4036. X#ifdef SCAN
  4037. X        do_error("macunpack: Premature EOF");
  4038. X#endif /* SCAN */
  4039. X        exit(1);
  4040. X        }
  4041. X    }
  4042. X    }
  4043. X}
  4044. X
  4045. SHAR_EOF
  4046. if test 2591 -ne "`wc -c < 'mcb.c'`"
  4047. then
  4048.     echo shar: "error transmitting 'mcb.c'" '(should have been 2591 characters)'
  4049. fi
  4050. fi
  4051. echo shar: "extracting 'makefile'" '(4554 characters)'
  4052. if test -f 'makefile'
  4053. then
  4054.     echo shar: "will not over-write existing file 'makefile'"
  4055. else
  4056. sed 's/^X//' << \SHAR_EOF > 'makefile'
  4057. XCFLAGS = -O $(CF)
  4058. X
  4059. XSRCS =    macunpack.c \
  4060. X    globals.c \
  4061. X    macbinary.c \
  4062. X    dir.c \
  4063. X    mcb.c \
  4064. X    bin.c \
  4065. X    jdw.c \
  4066. X    stf.c \
  4067. X    lzc.c \
  4068. X    pit.c \
  4069. X    sit.c \
  4070. X    dia.c \
  4071. X    cpt.c \
  4072. X    zma.c \
  4073. X    lzh.c \
  4074. X    dd.c \
  4075. X    de_huffman.c \
  4076. X    de_compress.c \
  4077. X    de_lzah.c \
  4078. X    de_lzh.c \
  4079. X    crc.c \
  4080. X    bits_be.c
  4081. X
  4082. XOBJS =    macunpack.o \
  4083. X    globals.o \
  4084. X    macbinary.o \
  4085. X    dir.o \
  4086. X    mcb.o \
  4087. X    bin.o \
  4088. X    jdw.o \
  4089. X    stf.o \
  4090. X    lzc.o \
  4091. X    pit.o \
  4092. X    sit.o \
  4093. X    dia.o \
  4094. X    cpt.o \
  4095. X    zma.o \
  4096. X    lzh.o \
  4097. X    dd.o \
  4098. X    de_huffman.o \
  4099. X    de_compress.o \
  4100. X    de_lzah.o \
  4101. X    de_lzh.o \
  4102. X    crc.o \
  4103. X    bits_be.o
  4104. X
  4105. XLIB =    ../crc/libcrc.a
  4106. XTNAME =    ../util/transname
  4107. XUNAME =    ../util/util
  4108. XONAME =    ../fileio/wrfile
  4109. XGNAME =    ../fileio/fileglob
  4110. XXOBJS =    $(TNAME).o $(UNAME).o $(ONAME).o $(GNAME).o
  4111. XXSRCS =    $(TNAME).c $(UNAME).c $(ONAME).c $(GNAME).c
  4112. XCRCS =    ../crc/arc.c ../crc/binhex.c ../crc/zip.c
  4113. X
  4114. Xmacunpack:    $(OBJS) $(LIB) $(XOBJS)
  4115. X    $(CC) $(CFLAGS) -o macunpack $(OBJS) $(XOBJS) $(LIB)
  4116. X
  4117. X$(LIB):    ../crc/makecrc.c
  4118. X    (cd ../crc; make CC=$(CC) CF="$(CF)" )
  4119. X
  4120. X$(TNAME).o:    $(TNAME).c
  4121. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  4122. X
  4123. X$(UNAME).o:    $(UNAME).c
  4124. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  4125. X
  4126. X$(ONAME).o:    $(ONAME).c
  4127. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  4128. X
  4129. X$(GNAME).o:    $(GNAME).c
  4130. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  4131. X
  4132. Xlint:
  4133. X    lint $(CF) $(LFLAGS) $(SRCS) $(XSRCS) $(CRCS)
  4134. X
  4135. Xclean:
  4136. X    -rm -f *.o
  4137. X
  4138. Xclobber:clean
  4139. X    -rm -f macunpack
  4140. X
  4141. Xmacunpack.o:    macunpack.h
  4142. Xmacunpack.o:    globals.h
  4143. Xmacunpack.o:    ../util/patchlevel.h
  4144. Xmacunpack.o:    ../fileio/wrfile.h
  4145. Xmacunpack.o:    ../fileio/wrfileopt.h
  4146. Xmacunpack.o:    ../fileio/kind.h
  4147. Xmacunpack.o:    ../util/util.h
  4148. Xglobals.o:    globals.h
  4149. Xglobals.o:    ../fileio/machdr.h
  4150. Xglobals.o:    ../fileio/wrfile.h
  4151. Xglobals.o:    ../fileio/kind.h
  4152. Xmacbinary.o:    macunpack.h
  4153. Xmacbinary.o:    globals.h
  4154. Xmacbinary.o:    zmahdr.h
  4155. Xmacbinary.o:    ../fileio/machdr.h
  4156. Xmacbinary.o:    ../fileio/wrfile.h
  4157. Xmacbinary.o:    ../fileio/kind.h
  4158. Xmacbinary.o:    ../util/util.h
  4159. Xdir.o:    globals.h
  4160. Xdir.o:    ../fileio/machdr.h
  4161. Xdir.o:    ../fileio/wrfile.h
  4162. Xdir.o:    ../util/util.h
  4163. Xdir.o:    ../util/masks.h
  4164. Xmcb.o:    globals.h
  4165. Xmcb.o:    ../fileio/machdr.h
  4166. Xmcb.o:    ../fileio/wrfile.h
  4167. Xmcb.o:    ../util/masks.h
  4168. Xmcb.o:    ../util/util.h
  4169. Xbin.o:    macunpack.h
  4170. Xbin.o:    globals.h
  4171. Xbin.o:    ../fileio/machdr.h
  4172. Xbin.o:    ../fileio/wrfile.h
  4173. Xbin.o:    ../fileio/kind.h
  4174. Xbin.o:    ../util/util.h
  4175. Xbin.o:    ../util/masks.h
  4176. Xjdw.o:    macunpack.h
  4177. Xjdw.o:    jdw.h
  4178. Xjdw.o:    globals.h
  4179. Xjdw.o:    huffman.h
  4180. Xjdw.o:    ../fileio/wrfile.h
  4181. Xjdw.o:    ../fileio/machdr.h
  4182. Xjdw.o:    ../util/util.h
  4183. Xjdw.o:    ../util/masks.h
  4184. Xstf.o:    macunpack.h
  4185. Xstf.o:    stf.h
  4186. Xstf.o:    globals.h
  4187. Xstf.o:    huffman.h
  4188. Xstf.o:    ../util/curtime.h
  4189. Xstf.o:    ../fileio/wrfile.h
  4190. Xstf.o:    ../fileio/machdr.h
  4191. Xstf.o:    ../util/util.h
  4192. Xlzc.o:    macunpack.h
  4193. Xlzc.o:    globals.h
  4194. Xlzc.o:    lzc.h
  4195. Xlzc.o:    ../util/util.h
  4196. Xlzc.o:    ../fileio/machdr.h
  4197. Xlzc.o:    ../fileio/wrfile.h
  4198. Xlzc.o:    ../util/masks.h
  4199. Xpit.o:    macunpack.h
  4200. Xpit.o:    ../fileio/fileglob.h
  4201. Xpit.o:    ../fileio/wrfile.h
  4202. Xpit.o:    ../fileio/kind.h
  4203. Xpit.o:    globals.h
  4204. Xpit.o:    pit.h
  4205. Xpit.o:    ../fileio/machdr.h
  4206. Xpit.o:    crc.h
  4207. Xpit.o:    ../util/masks.h
  4208. Xpit.o:    ../util/util.h
  4209. Xpit.o:    huffman.h
  4210. Xsit.o:    macunpack.h
  4211. Xsit.o:    globals.h
  4212. Xsit.o:    sit.h
  4213. Xsit.o:    crc.h
  4214. Xsit.o:    ../util/util.h
  4215. Xsit.o:    ../fileio/machdr.h
  4216. Xsit.o:    ../fileio/wrfile.h
  4217. Xsit.o:    ../fileio/kind.h
  4218. Xsit.o:    ../util/masks.h
  4219. Xsit.o:    huffman.h
  4220. Xdia.o:    macunpack.h
  4221. Xdia.o:    globals.h
  4222. Xdia.o:    dia.h
  4223. Xdia.o:    ../util/curtime.h
  4224. Xdia.o:    ../util/masks.h
  4225. Xdia.o:    ../fileio/machdr.h
  4226. Xdia.o:    ../fileio/wrfile.h
  4227. Xdia.o:    ../fileio/kind.h
  4228. Xdia.o:    ../util/util.h
  4229. Xcpt.o:    macunpack.h
  4230. Xcpt.o:    globals.h
  4231. Xcpt.o:    cpt.h
  4232. Xcpt.o:    crc.h
  4233. Xcpt.o:    ../util/util.h
  4234. Xcpt.o:    ../fileio/machdr.h
  4235. Xcpt.o:    ../fileio/wrfile.h
  4236. Xcpt.o:    ../fileio/kind.h
  4237. Xcpt.o:    ../util/masks.h
  4238. Xcpt.o:    huffman.h
  4239. Xzma.o:    macunpack.h
  4240. Xzma.o:    globals.h
  4241. Xzma.o:    zma.h
  4242. Xzma.o:    crc.h
  4243. Xzma.o:    ../fileio/machdr.h
  4244. Xzma.o:    ../fileio/wrfile.h
  4245. Xzma.o:    ../fileio/kind.h
  4246. Xzma.o:    ../util/masks.h
  4247. Xzma.o:    ../util/util.h
  4248. Xlzh.o:    macunpack.h
  4249. Xlzh.o:    globals.h
  4250. Xlzh.o:    lzh.h
  4251. Xlzh.o:    crc.h
  4252. Xlzh.o:    ../fileio/wrfile.h
  4253. Xlzh.o:    ../fileio/machdr.h
  4254. Xlzh.o:    ../util/masks.h
  4255. Xlzh.o:    ../util/util.h
  4256. Xlzh.o:    bits_be.h
  4257. Xdd.o:    macunpack.h
  4258. Xdd.o:    globals.h
  4259. Xdd.o:    dd.h
  4260. Xdd.o:    crc.h
  4261. Xdd.o:    ../fileio/machdr.h
  4262. Xdd.o:    ../fileio/wrfile.h
  4263. Xdd.o:    ../fileio/fileglob.h
  4264. Xdd.o:    ../util/masks.h
  4265. Xdd.o:    ../util/util.h
  4266. Xde_huffman.o:    macunpack.h
  4267. Xde_huffman.o:    globals.h
  4268. Xde_huffman.o:    ../util/masks.h
  4269. Xde_huffman.o:    huffman.h
  4270. Xde_huffman.o:    ../fileio/wrfile.h
  4271. Xde_huffman.o:    ../util/util.h
  4272. Xde_compress.o:    macunpack.h
  4273. Xde_compress.o:    globals.h
  4274. Xde_compress.o:    ../fileio/wrfile.h
  4275. Xde_lzah.o:    macunpack.h
  4276. Xde_lzah.o:    globals.h
  4277. Xde_lzah.o:    ../util/masks.h
  4278. Xde_lzah.o:    ../fileio/wrfile.h
  4279. Xde_lzh.o:    macunpack.h
  4280. Xde_lzh.o:    globals.h
  4281. Xde_lzh.o:    ../util/masks.h
  4282. Xde_lzh.o:    ../fileio/wrfile.h
  4283. Xde_lzh.o:    bits_be.h
  4284. Xbits_be.o:    ../util/masks.h
  4285. Xbits_be.o:    bits_be.h
  4286. X
  4287. SHAR_EOF
  4288. if test 4554 -ne "`wc -c < 'makefile'`"
  4289. then
  4290.     echo shar: "error transmitting 'makefile'" '(should have been 4554 characters)'
  4291. fi
  4292. fi
  4293. echo shar: "extracting 'cpt.c'" '(17640 characters)'
  4294. if test -f 'cpt.c'
  4295. then
  4296.     echo shar: "will not over-write existing file 'cpt.c'"
  4297. else
  4298. sed 's/^X//' << \SHAR_EOF > 'cpt.c'
  4299. X#include "macunpack.h"
  4300. X#ifdef DD
  4301. X#ifndef CPT
  4302. X#define CPT
  4303. X#endif /* CPT */
  4304. X#endif /* DD */
  4305. X#ifdef CPT
  4306. X#include "globals.h"
  4307. X#include "cpt.h"
  4308. X#include "crc.h"
  4309. X#include "../util/util.h"
  4310. X#include "../fileio/machdr.h"
  4311. X#include "../fileio/wrfile.h"
  4312. X#include "../fileio/kind.h"
  4313. X#include "../util/masks.h"
  4314. X#include "huffman.h"
  4315. X
  4316. X#define    ESC1        0x81
  4317. X#define    ESC2        0x82
  4318. X#define NONESEEN    0
  4319. X#define ESC1SEEN    1
  4320. X#define ESC2SEEN    2
  4321. X
  4322. Xextern char *malloc();
  4323. Xextern char *realloc();
  4324. Xextern int free();
  4325. X
  4326. Xstatic void cpt_uncompact();
  4327. Xstatic unsigned char *cpt_data;
  4328. Xstatic unsigned long cpt_datamax;
  4329. Xstatic unsigned long cpt_datasize;
  4330. Xstatic unsigned char cpt_LZbuff[CIRCSIZE];
  4331. Xstatic unsigned int cpt_LZptr;
  4332. Xstatic unsigned char *cpt_char;
  4333. Xstatic unsigned long cpt_crc;
  4334. Xstatic unsigned long cpt_inlength;
  4335. Xstatic unsigned long cpt_outlength;
  4336. Xstatic int cpt_outstat;
  4337. Xstatic unsigned char cpt_savechar;
  4338. Xstatic unsigned long cpt_newbits;
  4339. Xstatic int cpt_bitsavail;
  4340. Xstatic int cpt_blocksize;
  4341. X/* Lengths is twice the max number of entries, and include slack. */
  4342. X#define SLACK    6
  4343. Xstatic node cpt_Hufftree[512 + SLACK], cpt_LZlength[128 + SLACK],
  4344. X        cpt_LZoffs[256 + SLACK];
  4345. X
  4346. Xstatic int readcpthdr();
  4347. Xstatic int cpt_filehdr();
  4348. Xstatic void cpt_folder();
  4349. Xstatic void cpt_uncompact();
  4350. Xstatic void cpt_wrfile();
  4351. Xvoid cpt_wrfile1();
  4352. Xstatic void cpt_outch();
  4353. Xstatic void cpt_rle();
  4354. Xstatic void cpt_rle_lzh();
  4355. Xstatic void cpt_readHuff();
  4356. Xstatic int cpt_get6bits();
  4357. Xstatic int cpt_getbit();
  4358. X
  4359. Xvoid cpt()
  4360. X{
  4361. X    struct cptHdr cpthdr;
  4362. X    struct fileHdr filehdr;
  4363. X    char *cptindex;
  4364. X    char *cptptr;
  4365. X    int i;
  4366. X
  4367. X    updcrc = zip_updcrc;
  4368. X    crcinit = zip_crcinit;
  4369. X    cpt_crc = INIT_CRC;
  4370. X    if(readcpthdr(&cpthdr) == 0) {
  4371. X    (void)fprintf(stderr, "Can't read archive header\n");
  4372. X#ifdef SCAN
  4373. X    do_error("macunpack: Can't read archive header");
  4374. X#endif /* SCAN */
  4375. X    exit(1);
  4376. X    }
  4377. X
  4378. X    cptindex = malloc((unsigned)(cpthdr.entries * FILEHDRSIZE));
  4379. X    if(cptindex == NULL) {
  4380. X    (void)fprintf(stderr, "Insufficient memory, aborting\n");
  4381. X    exit(1);
  4382. X    }
  4383. X    cptptr = cptindex;
  4384. X    if(fread(cptptr, 1, (int)cpthdr.commentsize, infp) != cpthdr.commentsize) {
  4385. X    (void)fprintf(stderr, "Can't read comment.\n");
  4386. X#ifdef SCAN
  4387. X    do_error("macunpack: Can't read comment");
  4388. X#endif /* SCAN */
  4389. X    exit(1);
  4390. X    }
  4391. X    cpt_crc = (*updcrc)(cpt_crc, cptptr, cpthdr.commentsize);
  4392. X
  4393. X    for(i = 0; i < cpthdr.entries; i++) {
  4394. X    *cptptr = getc(infp);
  4395. X    cpt_crc = (*updcrc)(cpt_crc, cptptr, 1);
  4396. X    if(*cptptr & 0x80) {
  4397. X        cptptr[F_FOLDER] = 1;
  4398. X        *cptptr &= 0x3f;
  4399. X    } else {
  4400. X        cptptr[F_FOLDER] = 0;
  4401. X    }
  4402. X    if(fread(cptptr + 1, 1, *cptptr, infp) != *cptptr) {
  4403. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  4404. X#ifdef SCAN
  4405. X        do_error("macunpack: Can't read file header");
  4406. X#endif /* SCAN */
  4407. X        exit(1);
  4408. X    }
  4409. X    cpt_crc = (*updcrc)(cpt_crc, cptptr + 1, *cptptr);
  4410. X    if(cptptr[F_FOLDER]) {
  4411. X        if(fread(cptptr + F_FOLDERSIZE, 1, 2, infp) != 2) {
  4412. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  4413. X#ifdef SCAN
  4414. X        do_error("macunpack: Can't read file header");
  4415. X#endif /* SCAN */
  4416. X        exit(1);
  4417. X        }
  4418. X        cpt_crc = (*updcrc)(cpt_crc, cptptr + F_FOLDERSIZE, 2);
  4419. X    } else {
  4420. X        if(fread(cptptr + F_VOLUME, 1, FILEHDRSIZE - F_VOLUME, infp) !=
  4421. X        FILEHDRSIZE - F_VOLUME) {
  4422. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  4423. X#ifdef SCAN
  4424. X        do_error("macunpack: Can't read file header");
  4425. X#endif /* SCAN */
  4426. X        exit(1);
  4427. X        }
  4428. X        cpt_crc = (*updcrc)(cpt_crc, cptptr + F_VOLUME,
  4429. X                FILEHDRSIZE - F_VOLUME);
  4430. X    }
  4431. X    cptptr += FILEHDRSIZE;
  4432. X    }
  4433. X    if(cpt_crc != cpthdr.hdrcrc) {
  4434. X    (void)fprintf(stderr, "Header CRC mismatch: got 0x%08x, need 0x%08x\n",
  4435. X        (int)cpthdr.hdrcrc, (int)cpt_crc);
  4436. X#ifdef SCAN
  4437. X    do_error("macunpack: Header CRC mismatch");
  4438. X#endif /* SCAN */
  4439. X    exit(1);
  4440. X    }
  4441. X
  4442. X    cptptr = cptindex;
  4443. X    for(i = 0; i < cpthdr.entries; i++) {
  4444. X    if(cpt_filehdr(&filehdr, cptptr) == -1) {
  4445. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  4446. X#ifdef SCAN
  4447. X        do_error("macunpack: Can't read file header");
  4448. X#endif /* SCAN */
  4449. X        exit(1);
  4450. X    }
  4451. X    if(filehdr.folder) {
  4452. X        cpt_folder(text, filehdr, cptptr);
  4453. X        i += filehdr.foldersize;
  4454. X        cptptr += filehdr.foldersize * FILEHDRSIZE;
  4455. X    } else {
  4456. X        cpt_uncompact(filehdr);
  4457. X    }
  4458. X    cptptr += FILEHDRSIZE;
  4459. X    }
  4460. X    (void)free(cptindex);
  4461. X}
  4462. X
  4463. Xstatic int readcpthdr(s)
  4464. Xstruct cptHdr *s;
  4465. X{
  4466. X    char temp[CHDRSIZE];
  4467. X
  4468. X    if(fread(temp, 1, CPTHDRSIZE, infp) != CPTHDRSIZE) {
  4469. X    return 0;
  4470. X    }
  4471. X
  4472. X    if(temp[C_SIGNATURE] != 1) {
  4473. X    (void)fprintf(stderr, "Not a Compactor file\n");
  4474. X    return 0;
  4475. X    }
  4476. X
  4477. X    cpt_datasize = get4(temp + C_IOFFSET);
  4478. X    s->offset = cpt_datasize;
  4479. X    if(cpt_datasize > cpt_datamax) {
  4480. X    if(cpt_datamax == 0) {
  4481. X        cpt_data = (unsigned char *)malloc((unsigned)cpt_datasize);
  4482. X    } else {
  4483. X        cpt_data = (unsigned char *)realloc((char *)cpt_data,
  4484. X                        (unsigned)cpt_datasize);
  4485. X    }
  4486. X    cpt_datamax = cpt_datasize;
  4487. X    }
  4488. X    if(cpt_data == NULL) {
  4489. X    (void)fprintf(stderr, "Insufficient memory, aborting\n");
  4490. X    exit(1);
  4491. X    }
  4492. X
  4493. X    if(fread((char *)(cpt_data + CPTHDRSIZE), 1,
  4494. X    (int)s->offset - CPTHDRSIZE, infp) != s->offset - CPTHDRSIZE) {
  4495. X    return 0;
  4496. X    }
  4497. X
  4498. X    if(fread(temp + CPTHDRSIZE, 1, CPTHDR2SIZE, infp) != CPTHDR2SIZE) {
  4499. X    return 0;
  4500. X    }
  4501. X
  4502. X    cpt_crc = (*updcrc)(cpt_crc, temp + CPTHDRSIZE + C_ENTRIES, 3);
  4503. X    s->hdrcrc = get4(temp + CPTHDRSIZE + C_HDRCRC);
  4504. X    s->entries = get2(temp + CPTHDRSIZE + C_ENTRIES);
  4505. X    s->commentsize = temp[CPTHDRSIZE + C_COMMENT];
  4506. X
  4507. X    return 1;
  4508. X}
  4509. X
  4510. Xstatic int cpt_filehdr(f, hdr)
  4511. Xstruct fileHdr *f;
  4512. Xchar *hdr;
  4513. X{
  4514. X    register int i;
  4515. X    int n;
  4516. X    char ftype[5], fauth[5];
  4517. X
  4518. X    for(i = 0; i < INFOBYTES; i++) {
  4519. X    info[i] = '\0';
  4520. X    }
  4521. X
  4522. X    n = hdr[F_FNAME] & BYTEMASK;
  4523. X    if(n > F_NAMELEN) {
  4524. X    n = F_NAMELEN;
  4525. X    }
  4526. X    info[I_NAMEOFF] = n;
  4527. X    copy(info + I_NAMEOFF + 1, hdr + F_FNAME + 1, n);
  4528. X    transname(hdr + F_FNAME + 1, text, n);
  4529. X
  4530. X    f->folder = hdr[F_FOLDER];
  4531. X    if(f->folder) {
  4532. X    f->foldersize = get2(hdr + F_FOLDERSIZE);
  4533. X    } else {
  4534. X    f->cptFlag = get2(hdr + F_CPTFLAG);
  4535. X    f->rsrcLength = get4(hdr + F_RSRCLENGTH);
  4536. X    f->dataLength = get4(hdr + F_DATALENGTH);
  4537. X    f->compRLength = get4(hdr + F_COMPRLENGTH);
  4538. X    f->compDLength = get4(hdr + F_COMPDLENGTH);
  4539. X    f->fileCRC = get4(hdr + F_FILECRC);
  4540. X    f->FndrFlags = get2(hdr + F_FNDRFLAGS);
  4541. X    f->filepos = get4(hdr + F_FILEPOS);
  4542. X    f->volume = hdr[F_VOLUME];
  4543. X    }
  4544. X
  4545. X    write_it = 1;
  4546. X    if(list) {
  4547. X    do_indent(indent);
  4548. X    if(f->folder) {
  4549. X        (void)fprintf(stderr, "folder=\"%s\"", text);
  4550. X    } else {
  4551. X        transname(hdr + F_FTYPE, ftype, 4);
  4552. X        transname(hdr + F_CREATOR, fauth, 4);
  4553. X        (void)fprintf(stderr,
  4554. X            "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  4555. X            text, ftype, fauth,
  4556. X            (long)f->dataLength, (long)f->rsrcLength);
  4557. X    }
  4558. X    if(info_only) {
  4559. X        write_it = 0;
  4560. X    }
  4561. X    if(query) {
  4562. X        write_it = do_query();
  4563. X    } else {
  4564. X        (void)fputc('\n', stderr);
  4565. X    }
  4566. X    }
  4567. X
  4568. X
  4569. X    if(write_it) {
  4570. X    define_name(text);
  4571. X
  4572. X    if(!f->folder) {
  4573. X        copy(info + I_TYPEOFF, hdr + F_FTYPE, 4);
  4574. X        copy(info + I_AUTHOFF, hdr + F_CREATOR, 4);
  4575. X        copy(info + I_FLAGOFF, hdr + F_FNDRFLAGS, 2);
  4576. X        copy(info + I_DLENOFF, hdr + F_DATALENGTH, 4);
  4577. X        copy(info + I_RLENOFF, hdr + F_RSRCLENGTH, 4);
  4578. X        copy(info + I_CTIMOFF, hdr + F_CREATIONDATE, 4);
  4579. X        copy(info + I_MTIMOFF, hdr + F_MODDATE, 4);
  4580. X    }
  4581. X    }
  4582. X    return 1;
  4583. X}
  4584. X
  4585. Xstatic void cpt_folder(name, fileh, cptptr)
  4586. Xchar *name;
  4587. Xstruct fileHdr fileh;
  4588. Xchar *cptptr;
  4589. X{
  4590. X    int i, nfiles;
  4591. X    char loc_name[64];
  4592. X    struct fileHdr filehdr;
  4593. X
  4594. X    for(i = 0; i < 64; i++) {
  4595. X    loc_name[i] = name[i];
  4596. X    }
  4597. X    if(write_it || info_only) {
  4598. X    cptptr += FILEHDRSIZE;
  4599. X    nfiles = fileh.foldersize;
  4600. X    if(write_it) {
  4601. X        do_mkdir(text, info);
  4602. X    }
  4603. X    indent++;
  4604. X    for(i = 0; i < nfiles; i++) {
  4605. X        if(cpt_filehdr(&filehdr, cptptr) == -1) {
  4606. X        (void)fprintf(stderr, "Can't read file header #%d\n", i+1);
  4607. X#ifdef SCAN
  4608. X        do_error("macunpack: Can't read file header");
  4609. X#endif /* SCAN */
  4610. X        exit(1);
  4611. X        }
  4612. X        if(filehdr.folder) {
  4613. X        cpt_folder(text, filehdr, cptptr);
  4614. X        i += filehdr.foldersize;
  4615. X        cptptr += filehdr.foldersize * FILEHDRSIZE;
  4616. X        } else {
  4617. X        cpt_uncompact(filehdr);
  4618. X        }
  4619. X        cptptr += FILEHDRSIZE;
  4620. X    }
  4621. X    if(write_it) {
  4622. X        enddir();
  4623. X    }
  4624. X    indent--;
  4625. X    if(list) {
  4626. X        do_indent(indent);
  4627. X        (void)fprintf(stderr, "leaving folder \"%s\"\n", loc_name);
  4628. X    }
  4629. X    }
  4630. X}
  4631. X
  4632. Xstatic void cpt_uncompact(filehdr)
  4633. Xstruct fileHdr filehdr;
  4634. X{
  4635. X    if(filehdr.cptFlag & 1) {
  4636. X    (void)fprintf(stderr, "\tFile is password protected, skipping file\n");
  4637. X#ifdef SCAN
  4638. X    do_idf("", PROTECTED);
  4639. X#endif /* SCAN */
  4640. X    return;
  4641. X    }
  4642. X    if(write_it) {
  4643. X    start_info(info, filehdr.rsrcLength, filehdr.dataLength);
  4644. X    cpt_crc = INIT_CRC;
  4645. X    cpt_char = cpt_data + filehdr.filepos;
  4646. X    }
  4647. X    if(verbose) {
  4648. X    (void)fprintf(stderr, "\tRsrc: ");
  4649. X    if(filehdr.compRLength == 0) {
  4650. X        (void)fprintf(stderr, "empty");
  4651. X    } else if(filehdr.cptFlag & 2) {
  4652. X        (void)fprintf(stderr, "RLE/LZH compressed (%4.1f%%)",
  4653. X            100.0 * filehdr.compRLength / filehdr.rsrcLength);
  4654. X    } else {
  4655. X        (void)fprintf(stderr, "RLE compressed (%4.1f%%)",
  4656. X            100.0 * filehdr.compRLength / filehdr.rsrcLength);
  4657. X    }
  4658. X    }
  4659. X    if(write_it) {
  4660. X    start_rsrc();
  4661. X    cpt_wrfile(filehdr.compRLength, filehdr.rsrcLength,
  4662. X           filehdr.cptFlag & 2);
  4663. X    cpt_char = cpt_data + filehdr.filepos + filehdr.compRLength;
  4664. X    }
  4665. X    if(verbose) {
  4666. X    (void)fprintf(stderr, ", Data: ");
  4667. X    if(filehdr.compDLength == 0) {
  4668. X        (void)fprintf(stderr, "empty");
  4669. X    } else if(filehdr.cptFlag & 4) {
  4670. X        (void)fprintf(stderr, "RLE/LZH compressed (%4.1f%%)",
  4671. X            100.0 * filehdr.compDLength / filehdr.dataLength);
  4672. X    } else {
  4673. X        (void)fprintf(stderr, "RLE compressed (%4.1f%%)",
  4674. X            100.0 * filehdr.compDLength / filehdr.dataLength);
  4675. X    }
  4676. X    }
  4677. X    if(write_it) {
  4678. X    start_data();
  4679. X    cpt_wrfile(filehdr.compDLength, filehdr.dataLength,
  4680. X           filehdr.cptFlag & 4);
  4681. X    if(filehdr.fileCRC != cpt_crc) {
  4682. X        (void)fprintf(stderr,
  4683. X        "CRC error on file: need 0x%08lx, got 0x%08lx\n",
  4684. X        (long)filehdr.fileCRC, (long)cpt_crc);
  4685. X#ifdef SCAN
  4686. X        do_error("macunpack: CRC error on file");
  4687. X#endif /* SCAN */
  4688. X        exit(1);
  4689. X    }
  4690. X    end_file();
  4691. X    }
  4692. X    if(verbose) {
  4693. X    (void)fprintf(stderr, ".\n");
  4694. X    }
  4695. X}
  4696. X
  4697. Xstatic void cpt_wrfile(ibytes, obytes, type)
  4698. Xunsigned long ibytes, obytes;
  4699. Xunsigned short type;
  4700. X{
  4701. X    if(ibytes == 0) {
  4702. X    return;
  4703. X    }
  4704. X    cpt_outstat = NONESEEN;
  4705. X    cpt_inlength = ibytes;
  4706. X    cpt_outlength = obytes;
  4707. X    cpt_LZptr = 0;
  4708. X    cpt_blocksize = 0x1fff0;
  4709. X    if(type == 0) {
  4710. X    cpt_rle();
  4711. X    } else {
  4712. X    cpt_rle_lzh();
  4713. X    }
  4714. X    cpt_crc = (*updcrc)(cpt_crc, out_buffer, obytes);
  4715. X}
  4716. X
  4717. Xvoid cpt_wrfile1(in_char, ibytes, obytes, type, blocksize)
  4718. Xunsigned char *in_char;
  4719. Xunsigned long ibytes, obytes, blocksize;
  4720. Xint type;
  4721. X{
  4722. X    cpt_char = in_char;
  4723. X    if(ibytes == 0) {
  4724. X    return;
  4725. X    }
  4726. X    cpt_outstat = NONESEEN;
  4727. X    cpt_inlength = ibytes;
  4728. X    cpt_outlength = obytes;
  4729. X    cpt_LZptr = 0;
  4730. X    cpt_blocksize = blocksize;
  4731. X    if(type == 0) {
  4732. X    cpt_rle();
  4733. X    } else {
  4734. X    cpt_rle_lzh();
  4735. X    }
  4736. X}
  4737. X
  4738. Xstatic void cpt_outch(ch)
  4739. Xunsigned char ch;
  4740. X{
  4741. X    cpt_LZbuff[cpt_LZptr++ & (CIRCSIZE - 1)] = ch;
  4742. X    switch(cpt_outstat) {
  4743. X    case NONESEEN:
  4744. X    if(ch == ESC1 && cpt_outlength != 1) {
  4745. X        cpt_outstat = ESC1SEEN;
  4746. X    } else {
  4747. X        cpt_savechar = ch;
  4748. X        *out_ptr++ = ch;
  4749. X        cpt_outlength--;
  4750. X    }
  4751. X    break;
  4752. X    case ESC1SEEN:
  4753. X    if(ch == ESC2) {
  4754. X        cpt_outstat = ESC2SEEN;
  4755. X    } else {
  4756. X        cpt_savechar = ESC1;
  4757. X        *out_ptr++ = ESC1;
  4758. X        cpt_outlength--;
  4759. X        if(cpt_outlength == 0) {
  4760. X        return;
  4761. X        }
  4762. X        if(ch == ESC1 && cpt_outlength != 1) {
  4763. X        return;
  4764. X        }
  4765. X        cpt_outstat = NONESEEN;
  4766. X        cpt_savechar = ch;
  4767. X        *out_ptr++ = ch;
  4768. X        cpt_outlength--;
  4769. X    }
  4770. X    break;
  4771. X    case ESC2SEEN:
  4772. X    cpt_outstat = NONESEEN;
  4773. X    if(ch != 0) {
  4774. X        while(--ch != 0) {
  4775. X        *out_ptr++ = cpt_savechar;
  4776. X        cpt_outlength--;
  4777. X        if(cpt_outlength == 0) {
  4778. X            return;
  4779. X        }
  4780. X        }
  4781. X    } else {
  4782. X        *out_ptr++ = ESC1;
  4783. X        cpt_outlength--;
  4784. X        if(cpt_outlength == 0) {
  4785. X        return;
  4786. X        }
  4787. X        cpt_savechar = ESC2;
  4788. X        *out_ptr++ = cpt_savechar;
  4789. X        cpt_outlength--;
  4790. X    }
  4791. X    }
  4792. X}
  4793. X
  4794. X/*---------------------------------------------------------------------------*/
  4795. X/*    Run length encoding                             */
  4796. X/*---------------------------------------------------------------------------*/
  4797. Xstatic void cpt_rle()
  4798. X{
  4799. X    while(cpt_inlength-- > 0) {
  4800. X    cpt_outch(*cpt_char++);
  4801. X    }
  4802. X}
  4803. X
  4804. X/*---------------------------------------------------------------------------*/
  4805. X/*    Run length encoding plus LZ compression plus Huffman encoding         */
  4806. X/*---------------------------------------------------------------------------*/
  4807. Xstatic void cpt_rle_lzh()
  4808. X{
  4809. X    int block_count;
  4810. X    unsigned int bptr;
  4811. X    int Huffchar, LZlength, LZoffs;
  4812. X
  4813. X    get_bit = cpt_getbit;
  4814. X    cpt_LZbuff[CIRCSIZE - 3] = 0;
  4815. X    cpt_LZbuff[CIRCSIZE - 2] = 0;
  4816. X    cpt_LZbuff[CIRCSIZE - 1] = 0;
  4817. X    cpt_LZptr = 0;
  4818. X    while(cpt_outlength != 0) {
  4819. X    cpt_readHuff(256, cpt_Hufftree);
  4820. X    cpt_readHuff(64, cpt_LZlength);
  4821. X    cpt_readHuff(128, cpt_LZoffs);
  4822. X    block_count = 0;
  4823. X    cpt_newbits = (*cpt_char++ << 8);
  4824. X    cpt_newbits = cpt_newbits | *cpt_char++;
  4825. X    cpt_newbits = cpt_newbits << 16;
  4826. X    cpt_bitsavail = 16;
  4827. X    while(block_count < cpt_blocksize && cpt_outlength != 0) {
  4828. X        if(cpt_getbit()) {
  4829. X        Huffchar = gethuffbyte(cpt_Hufftree);
  4830. X        cpt_outch((unsigned char)Huffchar);
  4831. X        block_count += 2;
  4832. X        } else {
  4833. X        LZlength = gethuffbyte(cpt_LZlength);
  4834. X        LZoffs = gethuffbyte(cpt_LZoffs);
  4835. X        LZoffs = (LZoffs << 6) | cpt_get6bits();
  4836. X        bptr = cpt_LZptr - LZoffs;
  4837. X        while(LZlength-- > 0) {
  4838. X            cpt_outch(cpt_LZbuff[bptr++ & (CIRCSIZE - 1)]);
  4839. X        }
  4840. X        block_count += 3;
  4841. X        }
  4842. X    }
  4843. X    }
  4844. X}
  4845. X
  4846. X/* Based on unimplod from unzip; difference are noted below. */
  4847. Xtypedef struct sf_entry {
  4848. X    int Value;
  4849. X    int BitLength;
  4850. X} sf_entry;
  4851. X
  4852. X/* See routine LoadTree.  The parameter tree (actually an array and
  4853. X   two integers) are only used locally in this version and hence locally
  4854. X   declared.  The parameter nodes has been renamed Hufftree.... */
  4855. Xstatic void cpt_readHuff(size, Hufftree)
  4856. Xint size;
  4857. Xstruct node *Hufftree;
  4858. X{
  4859. X    sf_entry tree_entry[256 + SLACK]; /* maximal number of elements */
  4860. X    int tree_entries;
  4861. X    int tree_MaxLength; /* finishes local declaration of tree */
  4862. X
  4863. X    int treeBytes, i, len;  /* declarations from ReadLengths */
  4864. X
  4865. X    /* declarations from SortLengths */
  4866. X    sf_entry *ejm1;
  4867. X    int j;
  4868. X    sf_entry *entry;
  4869. X/*  int i already above */
  4870. X    sf_entry tmp;
  4871. X    int entries;
  4872. X    unsigned a, b;
  4873. X
  4874. X    /* declarations from GenerateTrees */
  4875. X    int codelen, lvlstart, next, parents;
  4876. X/*  int i, j already above */
  4877. X
  4878. X    /* for Compactor */
  4879. X    int tree_count[32];
  4880. X    /* end declarations */
  4881. X
  4882. X    /* next paraphrased from ReadLengths with adaption for Compactor. */
  4883. X    treeBytes = *cpt_char++;
  4884. X    if(size < treeBytes * 2) { /* too many entries, something is wrong! */
  4885. X    (void)fprintf(stderr, "Bytes is: %d, expected: %d\n", treeBytes,
  4886. X        size / 2);
  4887. X#ifdef SCAN
  4888. X    do_error("macunpack: error in coding tree");
  4889. X#endif /* SCAN */
  4890. X    exit(1);
  4891. X    }
  4892. X    for(i = 0; i < 32; i++) {
  4893. X    tree_count[i] = 0;
  4894. X    }
  4895. X    i = 0;
  4896. X    tree_MaxLength = 0;
  4897. X    tree_entries = 0;
  4898. X    while(treeBytes-- > 0) { /* adaption for Compactor */
  4899. X    len = (*cpt_char) >> 4;
  4900. X    if(len != 0) { /* only if length unequal zero */
  4901. X        if(len > tree_MaxLength) {
  4902. X        tree_MaxLength = len;
  4903. X        }
  4904. X        tree_count[len]++;
  4905. X        tree_entry[tree_entries].Value = i;
  4906. X        tree_entry[tree_entries++].BitLength = len;
  4907. X    }
  4908. X    i++;
  4909. X    len = *cpt_char++ & NIBBLEMASK;
  4910. X    if(len != 0) { /* only if length unequal zero */
  4911. X        if(len > tree_MaxLength) {
  4912. X        tree_MaxLength = len;
  4913. X        }
  4914. X        tree_count[len]++;
  4915. X        tree_entry[tree_entries].Value = i;
  4916. X        tree_entry[tree_entries++].BitLength = len;
  4917. X    }
  4918. X    i++;
  4919. X    }
  4920. X
  4921. X    /* Compactor allows unused trailing codes in its Huffman tree! */
  4922. X    j = 0;
  4923. X    for(i = 0; i <= tree_MaxLength; i++) {
  4924. X    j = (j << 1) + tree_count[i];
  4925. X    }
  4926. X    j = (1 <<tree_MaxLength) - j;
  4927. X    /* Insert the unused entries for sorting purposes. */
  4928. X    for(i = 0; i < j; i++) {
  4929. X    tree_entry[tree_entries].Value = size;
  4930. X    tree_entry[tree_entries++].BitLength = tree_MaxLength;
  4931. X    }
  4932. X
  4933. X    /* adaption from SortLengths */
  4934. X    entry = &(tree_entry[0]);
  4935. X    entries = tree_entries;
  4936. X    for(i = 0; ++i < entries;) {
  4937. X    tmp = entry[i];
  4938. X    b = tmp.BitLength;
  4939. X    j = i;
  4940. X    while((j > 0) && ((a = (ejm1 = &(entry[j - 1]))->BitLength) >= b)) {
  4941. X        if((a == b) && (ejm1->Value <= tmp.Value)) {
  4942. X        break;
  4943. X        }
  4944. X        *(ejm1 + 1) = *ejm1;
  4945. X        --j;
  4946. X    }
  4947. X    entry[j] = tmp;
  4948. X    }
  4949. X
  4950. X    /* Adapted from GenerateTrees */
  4951. X    i = tree_entries - 1;
  4952. X    /* starting at the upper end (and reversing loop) because of Compactor */
  4953. X    lvlstart = next = size * 2 + SLACK - 1;
  4954. X    /* slight adaption because of different node format used */
  4955. X    for(codelen = tree_MaxLength; codelen >= 1; --codelen) {
  4956. X    while((i >= 0) && (tree_entry[i].BitLength == codelen)) {
  4957. X        Hufftree[next].byte = tree_entry[i].Value;
  4958. X        Hufftree[next].flag = 1;
  4959. X        next--;
  4960. X        i--;
  4961. X    }
  4962. X    parents = next;
  4963. X    if(codelen > 1) {
  4964. X        /* reversed loop */
  4965. X        for(j = lvlstart; j > parents + 1; j-= 2) {
  4966. X        Hufftree[next].one = &(Hufftree[j]);
  4967. X        Hufftree[next].zero = &(Hufftree[j - 1]);
  4968. X        Hufftree[next].flag = 0;
  4969. X        next--;
  4970. X        }
  4971. X    }
  4972. X    lvlstart = parents;
  4973. X    }
  4974. X    Hufftree[0].one = &(Hufftree[next + 2]);
  4975. X    Hufftree[0].zero = &(Hufftree[next + 1]);
  4976. X    Hufftree[0].flag = 0;
  4977. X}
  4978. X
  4979. Xstatic int cpt_get6bits()
  4980. X{
  4981. Xint b = 0, cn;
  4982. X
  4983. X    b = (cpt_newbits >> 26) & 0x3f;
  4984. X    cpt_bitsavail -= 6;
  4985. X    cpt_newbits <<= 6;
  4986. X    if(cpt_bitsavail < 16) {
  4987. X    cn = (*cpt_char++ << 8);
  4988. X    cn |= *cpt_char++;
  4989. X    cpt_newbits |= (cn << (16 - cpt_bitsavail));
  4990. X    cpt_bitsavail += 16;
  4991. X    }
  4992. X    return b;
  4993. X}
  4994. X
  4995. Xstatic int cpt_getbit()
  4996. X{
  4997. Xint b;
  4998. X
  4999. X    b = (cpt_newbits >> 31) & 1;
  5000. X    cpt_bitsavail--;
  5001. X    if(cpt_bitsavail < 16) {
  5002. X    cpt_newbits |= (*cpt_char++ << 8);
  5003. X    cpt_newbits |= *cpt_char++;
  5004. X    cpt_bitsavail += 16;
  5005. X    }
  5006. X    cpt_newbits <<= 1;
  5007. X    return b;
  5008. X}
  5009. X#else /* CPT */
  5010. Xint cpt; /* keep lint and some compilers happy */
  5011. X#endif /* CPT */
  5012. X
  5013. SHAR_EOF
  5014. if test 17640 -ne "`wc -c < 'cpt.c'`"
  5015. then
  5016.     echo shar: "error transmitting 'cpt.c'" '(should have been 17640 characters)'
  5017. fi
  5018. fi
  5019. echo shar: "extracting 'zma.c'" '(9528 characters)'
  5020. if test -f 'zma.c'
  5021. then
  5022.     echo shar: "will not over-write existing file 'zma.c'"
  5023. else
  5024. sed 's/^X//' << \SHAR_EOF > 'zma.c'
  5025. X#include "macunpack.h"
  5026. X#ifdef ZMA
  5027. X#include "globals.h"
  5028. X#include "zma.h"
  5029. X#include "crc.h"
  5030. X#include "../fileio/machdr.h"
  5031. X#include "../fileio/wrfile.h"
  5032. X#include "../fileio/kind.h"
  5033. X#include "../util/masks.h"
  5034. X#include "../util/util.h"
  5035. X
  5036. Xextern char *malloc();
  5037. Xextern char *realloc();
  5038. Xextern void de_lzh();
  5039. X
  5040. X/* We do allow for possible backpointing, so we allocate the archive in core */
  5041. Xstatic char *zma_archive;
  5042. Xstatic char *zma_current;
  5043. Xstatic char *zma_filestart;
  5044. Xstatic unsigned long zma_length;
  5045. Xstatic long zma_archlength;
  5046. X
  5047. Xstatic int zma_filehdr();
  5048. Xstatic void zma_folder();
  5049. Xstatic void zma_mooz();
  5050. Xstatic void zma_wrfile();
  5051. Xstatic void zma_nocomp();
  5052. Xstatic void zma_lzh();
  5053. X
  5054. Xvoid zma(start, length)
  5055. X    char *start;
  5056. X    unsigned long length;
  5057. X{
  5058. X    struct fileHdr filehdr;
  5059. X    int i, toread;
  5060. X
  5061. X    if(length != 0) {
  5062. X    if(zma_archlength < length) {
  5063. X        if(zma_archlength == 0) {
  5064. X        zma_archive = malloc((unsigned)length);
  5065. X        } else {
  5066. X        zma_archive = realloc(zma_archive, (unsigned)length);
  5067. X        }
  5068. X        zma_archlength = length;
  5069. X        if(zma_archive == NULL) {
  5070. X        (void)fprintf(stderr, "Insufficient memory, aborting\n");
  5071. X        exit(1);
  5072. X        }
  5073. X    }
  5074. X    if(fread(zma_archive, 1, (int)length, infp) != length) {
  5075. X        (void)fprintf(stderr, "Can't read archive.\n");
  5076. X#ifdef SCAN
  5077. X        do_error("macunpack: Can't read archive");
  5078. X#endif /* SCAN */
  5079. X        exit(1);
  5080. X    }
  5081. X    zma_length = get4(zma_archive + ZMAHDRS + 1);
  5082. X    if(zma_length != length) {
  5083. X        (void)fprintf(stderr, "Archive length mismatch.\n");
  5084. X#ifdef SCAN
  5085. X        do_error("macunpack: Archive length mismatch");
  5086. X#endif /* SCAN */
  5087. X        exit(1);
  5088. X    }
  5089. X    } else {
  5090. X    zma_length =  get4(start + ZMAHDRS + 1);
  5091. X    if(zma_archlength < zma_length) {
  5092. X        if(zma_archlength == 0) {
  5093. X        zma_archive = malloc((unsigned)zma_length);
  5094. X        } else {
  5095. X        zma_archive = realloc(zma_archive, (unsigned)zma_length);
  5096. X        }
  5097. X        zma_archlength = zma_length;
  5098. X        if(zma_archive == NULL) {
  5099. X        (void)fprintf(stderr, "Insufficient memory, aborting\n");
  5100. X        exit(1);
  5101. X        }
  5102. X    }
  5103. X    if(zma_archive == NULL) {
  5104. X        (void)fprintf(stderr, "Insufficient memory, aborting\n");
  5105. X        exit(1);
  5106. X    }
  5107. X    for(i = 0; i <= ZMAHDRS2; i++) {
  5108. X        zma_archive[i] = start[i];
  5109. X    }
  5110. X    toread = zma_length - ZMAHDRS2 - 1;
  5111. X    if(fread(zma_archive + ZMAHDRS2 + 1, 1, toread, infp) != toread) {
  5112. X        (void)fprintf(stderr, "Can't read archive.\n");
  5113. X#ifdef SCAN
  5114. X        do_error("macunpack: Can't read archive");
  5115. X#endif /* SCAN */
  5116. X        exit(1);
  5117. X    }
  5118. X    }
  5119. X    /* Consistency checks */
  5120. X    if(zma_archive[0] != 0) {
  5121. X    (void)fprintf(stderr, "Not a \"Zoom\" archive after all, aborting\n");
  5122. X    exit(1);
  5123. X    }
  5124. X    if(strncmp(zma_archive + 1, ZMAHDR, ZMAHDRS)) {
  5125. X    (void)fprintf(stderr, "Not a \"Zoom\" archive after all, aborting\n");
  5126. X    exit(1);
  5127. X    }
  5128. X    zma_current = zma_archive + 8;
  5129. X    updcrc = arc_updcrc;
  5130. X    crcinit = arc_crcinit;
  5131. X    while(zma_current != zma_archive) {
  5132. X    if(zma_filehdr(&filehdr, 0) == -1) {
  5133. X        (void)fprintf(stderr, "Can't find file header./n");
  5134. X#ifdef SCAN
  5135. X        do_error("macunpack: Can't find file header");
  5136. X#endif /* SCAN */
  5137. X        exit(1);
  5138. X    }
  5139. X    zma_filestart = zma_current + filehdr.hlen;
  5140. X    if(filehdr.what == z_dir) {
  5141. X        zma_folder(filehdr);
  5142. X    } else {
  5143. X        zma_mooz(filehdr);
  5144. X    }
  5145. X    zma_current = zma_archive + filehdr.next;
  5146. X    }
  5147. X}
  5148. X
  5149. Xstatic int zma_filehdr(f, skip)
  5150. Xstruct fileHdr *f;
  5151. Xint skip;
  5152. X{
  5153. X    register int i;
  5154. X    int n;
  5155. X    char ftype[5], fauth[5];
  5156. X
  5157. X    if(zma_current - zma_archive + Z_HDRSIZE > zma_length) {
  5158. X    return -1;
  5159. X    }
  5160. X    for(i = 0; i < INFOBYTES; i++) {
  5161. X    info[i] = '\0';
  5162. X    }
  5163. X
  5164. X    n = zma_current[Z_FNAME] & BYTEMASK;
  5165. X    if(n > F_NAMELEN) {
  5166. X    n = F_NAMELEN;
  5167. X    }
  5168. X    info[I_NAMEOFF] = n;
  5169. X    copy(info + I_NAMEOFF + 1, zma_current + Z_FNAME + 1, n);
  5170. X    transname(zma_current + Z_FNAME + 1, text, n);
  5171. X
  5172. X    f->what = zma_current[Z_WHAT];
  5173. X    f->rsrcLength = get4(zma_current + Z_URLEN);
  5174. X    f->dataLength = get4(zma_current + Z_UDLEN);
  5175. X    f->compRLength = get4(zma_current + Z_CRLEN);
  5176. X    f->compDLength = get4(zma_current + Z_CDLEN);
  5177. X    f->rsrcCRC = get2(zma_current + Z_RCRC);
  5178. X    f->dataCRC = get2(zma_current + Z_DCRC);
  5179. X    f->hlen = zma_current[Z_HLEN];
  5180. X    f->next = get4(zma_current + Z_NEXT);
  5181. X    if(f->what == z_dir) { /* A hack */
  5182. X    f->conts = get4(zma_current + Z_AUTH);
  5183. X    }
  5184. X    /* Set rsrc fork sizes correctly */
  5185. X    f->rsrcLength -= f->dataLength;
  5186. X    f->compRLength -= f->compDLength;
  5187. X
  5188. X    write_it = !skip;
  5189. X    if(f->what & 0x80) {
  5190. X    write_it = 0;
  5191. X    f->what = -f->what;
  5192. X    f->deleted = 1;
  5193. X    return 0;
  5194. X    }
  5195. X    f->deleted = 0;
  5196. X    if(list && !skip) {
  5197. X    do_indent(indent);
  5198. X    if(f->what == z_dir) {
  5199. X        (void)fprintf(stderr, "folder=\"%s\"", text);
  5200. X    } else {
  5201. X        transname(zma_current + Z_TYPE, ftype, 4);
  5202. X        transname(zma_current + Z_AUTH, fauth, 4);
  5203. X        (void)fprintf(stderr,
  5204. X            "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  5205. X            text, ftype, fauth,
  5206. X            (long)f->dataLength, (long)f->rsrcLength);
  5207. X    }
  5208. X    switch(f->what) {
  5209. X    case z_plug:
  5210. X        (void)fputc('\n', stderr);
  5211. X        (void)fprintf(stderr,
  5212. X            "\tFile uses custom processing, cannot handle.\n");
  5213. X        write_it = 0;
  5214. X        return 0;
  5215. X    case z_dir:
  5216. X    case z_file:
  5217. X    case z_plain:
  5218. X        break;
  5219. X    default:
  5220. X        (void)fputc('\n', stderr);
  5221. X        (void)fprintf(stderr,
  5222. X            "\tEh, do not understand this (%d); skipped.\n", f->what);
  5223. X        write_it = 0;
  5224. X        return 0;
  5225. X    }
  5226. X
  5227. X    if(info_only) {
  5228. X        write_it = 0;
  5229. X    }
  5230. X    if(query) {
  5231. X        write_it = do_query();
  5232. X    } else {
  5233. X        (void)fputc('\n', stderr);
  5234. X    }
  5235. X    }
  5236. X
  5237. X
  5238. X    if(write_it) {
  5239. X    define_name(text);
  5240. X
  5241. X    if(f->what != z_dir) {
  5242. X        copy(info + I_TYPEOFF, zma_current + Z_TYPE, 4);
  5243. X        copy(info + I_AUTHOFF, zma_current + Z_AUTH, 4);
  5244. X        copy(info + I_FLAGOFF, zma_current + Z_FLAGS, 2);
  5245. X        copy(info + I_DLENOFF, zma_current + Z_UDLEN, 4);
  5246. X        put4(zma_current + Z_URLEN, f->rsrcLength);
  5247. X        copy(info + I_RLENOFF, zma_current + Z_URLEN, 4);
  5248. X        copy(info + I_CTIMOFF, zma_current + Z_MDATE, 4);
  5249. X        copy(info + I_MTIMOFF, zma_current + Z_MDATE, 4);
  5250. X    }
  5251. X    }
  5252. X    return 1;
  5253. X}
  5254. X
  5255. Xstatic void zma_folder(fhdr)
  5256. Xstruct fileHdr fhdr;
  5257. X{
  5258. X    int i;
  5259. X    char loc_name[64];
  5260. X    struct fileHdr filehdr;
  5261. X
  5262. X    for(i = 0; i < 64; i++) {
  5263. X    loc_name[i] = text[i];
  5264. X    }
  5265. X    zma_current = zma_archive + fhdr.conts;
  5266. X    if(write_it || info_only) {
  5267. X    if(write_it) {
  5268. X        do_mkdir(text, info);
  5269. X    }
  5270. X    indent++;
  5271. X    while(zma_current != zma_archive) {
  5272. X        if(zma_filehdr(&filehdr, 0) == -1) {
  5273. X        (void)fprintf(stderr, "Can't find file header.\n");
  5274. X#ifdef SCAN
  5275. X        do_error("macunpack: Can't find file header");
  5276. X#endif /* SCAN */
  5277. X        exit(1);
  5278. X        }
  5279. X        zma_filestart = zma_current + filehdr.hlen;
  5280. X        if(filehdr.what == z_dir) {
  5281. X        zma_folder(filehdr);
  5282. X        } else {
  5283. X        zma_mooz(filehdr);
  5284. X        }
  5285. X        zma_current = zma_archive + filehdr.next;
  5286. X    }
  5287. X    if(write_it) {
  5288. X        enddir();
  5289. X    }
  5290. X    indent--;
  5291. X    if(list) {
  5292. X        do_indent(indent);
  5293. X        (void)fprintf(stderr, "leaving folder \"%s\"\n", loc_name);
  5294. X    }
  5295. X    }
  5296. X}
  5297. X
  5298. Xstatic void zma_mooz(filehdr)
  5299. Xstruct fileHdr filehdr;
  5300. X{
  5301. X    unsigned long crc;
  5302. X
  5303. X    if(write_it) {
  5304. X    start_info(info, filehdr.rsrcLength, filehdr.dataLength);
  5305. X    }
  5306. X    if(verbose) {
  5307. X    (void)fprintf(stderr, "\tData: ");
  5308. X    }
  5309. X    if(write_it) {
  5310. X    start_data();
  5311. X    }
  5312. X    zma_wrfile(filehdr.compDLength, filehdr.dataLength, filehdr.what);
  5313. X    if(write_it) {
  5314. X    crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.dataLength);
  5315. X    if(filehdr.dataCRC != crc) {
  5316. X        (void)fprintf(stderr,
  5317. X        "CRC error on data fork: need 0x%04x, got 0x%04x\n",
  5318. X        (int)filehdr.dataCRC, (int)crc);
  5319. X#ifdef SCAN
  5320. X        do_error("macunpack: CRC error on data fork");
  5321. X#endif /* SCAN */
  5322. X        exit(1);
  5323. X    }
  5324. X    }
  5325. X    if(verbose) {
  5326. X    (void)fprintf(stderr, ", Rsrc: ");
  5327. X    }
  5328. X    if(write_it) {
  5329. X    start_rsrc();
  5330. X    }
  5331. X    zma_wrfile(filehdr.compRLength, filehdr.rsrcLength, filehdr.what);
  5332. X    if(write_it) {
  5333. X    crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.rsrcLength);
  5334. X    if(filehdr.rsrcCRC != crc) {
  5335. X        (void)fprintf(stderr,
  5336. X        "CRC error on resource fork: need 0x%04x, got 0x%04x\n",
  5337. X        (int)filehdr.rsrcCRC, (int)crc);
  5338. X#ifdef SCAN
  5339. X        do_error("macunpack: CRC error on resource fork");
  5340. X#endif /* SCAN */
  5341. X        exit(1);
  5342. X    }
  5343. X    end_file();
  5344. X    }
  5345. X    if(verbose) {
  5346. X    (void)fprintf(stderr, ".\n");
  5347. X    }
  5348. X}
  5349. X
  5350. Xstatic void zma_wrfile(ibytes, obytes, type)
  5351. Xunsigned long ibytes, obytes;
  5352. Xchar type;
  5353. X{
  5354. X    if(ibytes == 0) {
  5355. X    if(verbose) {
  5356. X        (void)fprintf(stderr, "empty");
  5357. X    }
  5358. X    return;
  5359. X    }
  5360. X    switch(type) {
  5361. X    case z_plain:        /* no compression */
  5362. X    if(verbose) {
  5363. X        (void)fprintf(stderr, "No compression");
  5364. X    }
  5365. X    if(write_it) {
  5366. X        zma_nocomp(ibytes);
  5367. X    }
  5368. X    break;
  5369. X    case z_file:        /* lzh compression */
  5370. X    if(verbose) {
  5371. X        (void)fprintf(stderr,
  5372. X            "LZH compressed (%4.1f%%)", 100.0 * ibytes / obytes);
  5373. X    }
  5374. X    if(write_it) {
  5375. X        zma_lzh(ibytes);
  5376. X    }
  5377. X    break;
  5378. X    default:
  5379. X    (void)fprintf(stderr, "Unknown compression method %2x\n", type);
  5380. X#ifdef SCAN
  5381. X    do_idf("", UNKNOWN);
  5382. X#endif /* SCAN */
  5383. X    exit(1);
  5384. X    }
  5385. X}
  5386. X
  5387. X/*---------------------------------------------------------------------------*/
  5388. X/*    No compression                                 */
  5389. X/*---------------------------------------------------------------------------*/
  5390. Xstatic void zma_nocomp(ibytes)
  5391. Xunsigned long ibytes;
  5392. X{
  5393. X    int n = ibytes;
  5394. X    char *ptr = out_buffer;
  5395. X
  5396. X    while(n-- > 0) {
  5397. X    *ptr++ = *zma_filestart++;
  5398. X    }
  5399. X}
  5400. X
  5401. X/*---------------------------------------------------------------------------*/
  5402. X/*    LZ compression plus Huffman encoding                     */
  5403. X/*---------------------------------------------------------------------------*/
  5404. Xstatic void zma_lzh(ibytes)
  5405. Xunsigned long ibytes;
  5406. X{
  5407. X    /* Controlled by ibutes only */
  5408. X    de_lzh((long)ibytes, (long)(-1), &zma_filestart, 13);
  5409. X}
  5410. X#else /* ZMA */
  5411. Xint zma; /* keep lint and some compilers happy */
  5412. X#endif /* ZMA */
  5413. X
  5414. SHAR_EOF
  5415. if test 9528 -ne "`wc -c < 'zma.c'`"
  5416. then
  5417.     echo shar: "error transmitting 'zma.c'" '(should have been 9528 characters)'
  5418. fi
  5419. fi
  5420. echo shar: "extracting 'lzh.c'" '(18707 characters)'
  5421. if test -f 'lzh.c'
  5422. then
  5423.     echo shar: "will not over-write existing file 'lzh.c'"
  5424. else
  5425. sed 's/^X//' << \SHAR_EOF > 'lzh.c'
  5426. X#include "macunpack.h"
  5427. X#ifdef LZH
  5428. X#include "globals.h"
  5429. X#include "lzh.h"
  5430. X#include "crc.h"
  5431. X#include "../fileio/wrfile.h"
  5432. X#include "../fileio/machdr.h"
  5433. X#include "../util/masks.h"
  5434. X#include "../util/util.h"
  5435. X#include "bits_be.h"
  5436. X
  5437. X#define LZ5LOOKAHEAD    18    /* look ahead buffer size for LArc */
  5438. X#define LZ5BUFFSIZE    8192
  5439. X#define LZ5MASK        8191
  5440. X#define LZSLOOKAHEAD    17
  5441. X#define LZSBUFFSIZE    4096
  5442. X#define LZSMASK        4095
  5443. X#define LZBUFFSIZE    8192    /* Max of above buffsizes */
  5444. X
  5445. Xextern char *malloc();
  5446. Xextern char *realloc();
  5447. Xextern void de_lzah();
  5448. Xextern unsigned char (*lzah_getbyte)();
  5449. Xextern void de_lzh();
  5450. X
  5451. Xtypedef struct methodinfo {
  5452. X    char *name;
  5453. X    int number;
  5454. X};
  5455. X
  5456. Xstatic struct methodinfo methods[] = {
  5457. X    {"-lh0-", lh0},
  5458. X    {"-lh1-", lh1},
  5459. X    {"-lh2-", lh2},
  5460. X    {"-lh3-", lh3},
  5461. X    {"-lh4-", lh4},
  5462. X    {"-lh5-", lh5},
  5463. X    {"-lz4-", lz4},
  5464. X    {"-lz5-", lz5},
  5465. X    {"-lzs-", lzs}
  5466. X};
  5467. Xstatic char *lzh_archive;
  5468. Xstatic char *lzh_pointer;
  5469. Xstatic char *lzh_data;
  5470. Xstatic char *lzh_finfo;
  5471. Xstatic int lzh_fsize;
  5472. Xstatic int lzh_kind;
  5473. Xstatic int oldsize;
  5474. Xstatic char *lzh_file;
  5475. Xstatic int lzh_filesize;
  5476. Xstatic char *lzh_current;
  5477. Xstatic char *tmp_out_ptr;
  5478. Xstatic char lzh_lzbuf[LZBUFFSIZE];
  5479. X
  5480. Xstatic int lzh_filehdr();
  5481. Xstatic int lzh_checkm();
  5482. Xstatic char *lzh_methname();
  5483. Xstatic void lzh_wrfile();
  5484. Xstatic void lzh_skip();
  5485. Xstatic void lzh_nocomp();
  5486. X#ifdef UNTESTED
  5487. Xstatic void lzh_lzss1();
  5488. Xstatic void lzh_lzss2();
  5489. X#endif /* UNTESTED */
  5490. Xstatic void lzh_lzah();
  5491. Xstatic unsigned char lzh_getbyte();
  5492. X#ifdef UNDEF
  5493. Xstatic void lzh_lh2();
  5494. Xstatic void lzh_lh3();
  5495. X#endif /* UNDEF */
  5496. X#ifdef UNTESTED
  5497. Xstatic void lzh_lzh12();
  5498. X#endif /* UNTESTED */
  5499. Xstatic void lzh_lzh13();
  5500. X
  5501. Xvoid lzh(kind)
  5502. Xint kind;
  5503. X{
  5504. X    struct fileHdr filehdr;
  5505. X    int m, i, j;
  5506. X    char loc_name[64];
  5507. X    char dirinfo[INFOBYTES];
  5508. X
  5509. X    updcrc = arc_updcrc;
  5510. X    crcinit = arc_crcinit;
  5511. X    write_it = 1;
  5512. X    lzh_fsize = 0;
  5513. X    lzh_kind = kind;
  5514. X    if(lzh_archive == NULL) {
  5515. X    lzh_archive = malloc((unsigned)in_data_size);
  5516. X    oldsize = in_data_size;
  5517. X    } else if(in_data_size > oldsize) {
  5518. X    lzh_archive = realloc(lzh_archive, (unsigned)in_data_size);
  5519. X    oldsize = in_data_size;
  5520. X    }
  5521. X    if(lzh_archive == NULL) {
  5522. X    (void)fprintf(stderr, "Insufficient memory for archive.\n");
  5523. X    exit(1);
  5524. X    }
  5525. X    if(fread(lzh_archive, 1, in_data_size, infp) != in_data_size) {
  5526. X    (void)fprintf(stderr, "Can't read archive.\n");
  5527. X#ifdef SCAN
  5528. X    do_error("macunpack: Can't read archive");
  5529. X#endif /* SCAN */
  5530. X    exit(1);
  5531. X    }
  5532. X    lzh_pointer = lzh_archive;
  5533. X    while(1) {
  5534. X    if(in_data_size == 0) {
  5535. X        break;
  5536. X    }
  5537. X    if(lzh_filehdr(&filehdr) == 0) {
  5538. X        break;
  5539. X    }
  5540. X    m = lzh_checkm(&filehdr);
  5541. X    if(m < 0) {
  5542. X        (void)fprintf(stderr,
  5543. X            "Skipping file: \"%s\"; unknown method: %.5s.\n",
  5544. X            text, filehdr.method);
  5545. X        lzh_skip(&filehdr);
  5546. X        continue;
  5547. X    }
  5548. X    if(!write_it) {
  5549. X        /*  We are skipping a folder.  Skip the file if lzh_finfo is a
  5550. X        prefix of or identical to the folder info in the file. */
  5551. X        if(lzh_fsize <= filehdr.extendsize &&
  5552. X           !strncmp(lzh_finfo, filehdr.extend, lzh_fsize)) {
  5553. X        /* It was true, so we skip. */
  5554. X        lzh_skip(&filehdr);
  5555. X        continue;
  5556. X        }
  5557. X        /*  We have left the folder we were skipping. */
  5558. X    }
  5559. X    /*  Now we must leave folders until lzh_finfo is a proper prefix or
  5560. X        identical to the folder info in the file. */
  5561. X    while(lzh_fsize > filehdr.extendsize ||
  5562. X          strncmp(lzh_finfo, filehdr.extend, lzh_fsize)) {
  5563. X        /*  Not a proper prefix, leave folder.  First determine which! */
  5564. X        i = lzh_fsize - 1;
  5565. X        while(--i >= 0 && lzh_finfo[i] != ':');
  5566. X        i = i + 1;
  5567. X        transname(lzh_finfo + i, loc_name, lzh_fsize - i - 1);
  5568. X        lzh_fsize = i;
  5569. X        if(write_it) {
  5570. X        indent--;
  5571. X        if(!info_only) {
  5572. X            enddir();
  5573. X        }
  5574. X        if(list) {
  5575. X            do_indent(indent);
  5576. X            (void)fprintf(stderr, "leaving folder \"%s\"\n", loc_name);
  5577. X        }
  5578. X        }
  5579. X        write_it = 1;
  5580. X    }
  5581. X    write_it = 1;
  5582. X    /*  lzh_finfo is a proper prefix or identical, just show so. */
  5583. X    lzh_finfo = filehdr.extend;
  5584. X    /*  Now enter directories while lzh_finfo is smaller than extend. */
  5585. X    while(lzh_fsize < filehdr.extendsize) {
  5586. X        i = lzh_fsize;
  5587. X        while(lzh_finfo[++i] != ':');
  5588. X        transname(lzh_finfo + lzh_fsize, loc_name, i - lzh_fsize);
  5589. X        for(j = 0; j < INFOBYTES; j++) {
  5590. X        dirinfo[j] = 0;
  5591. X        }
  5592. X        dirinfo[I_NAMEOFF] = i - lzh_fsize;
  5593. X        copy(dirinfo + I_NAMEOFF + 1, lzh_finfo + lzh_fsize, i - lzh_fsize);
  5594. X        lzh_fsize = i + 1;
  5595. X        if(list) {
  5596. X        do_indent(indent);
  5597. X        (void)fprintf(stderr, "folder=\"%s\"", loc_name);
  5598. X        if(query) {
  5599. X            write_it = do_query();
  5600. X        } else {
  5601. X            (void)fputc('\n', stderr);
  5602. X        }
  5603. X        if(write_it) {
  5604. X            indent++;
  5605. X        }
  5606. X        }
  5607. X        if(write_it && !info_only) {
  5608. X        do_mkdir(loc_name, dirinfo);
  5609. X        }
  5610. X        if(!write_it) {
  5611. X        break;
  5612. X        }
  5613. X    }
  5614. X    if(!write_it) {
  5615. X        lzh_skip(&filehdr);
  5616. X    } else {
  5617. X        lzh_wrfile(&filehdr, m);
  5618. X    }
  5619. X    }
  5620. X    /*  Leaving some more directories! */
  5621. X    while(lzh_fsize != 0) {
  5622. X    i = lzh_fsize - 1;
  5623. X    while(--i >= 0 && lzh_finfo[i] != ':');
  5624. X    i = i + 1;
  5625. X    transname(lzh_finfo + i, loc_name, lzh_fsize - i - 1);
  5626. X    lzh_fsize = i;
  5627. X    if(write_it) {
  5628. X    }
  5629. X    if(write_it) {
  5630. X        indent--;
  5631. X        if(!info_only) {
  5632. X        enddir();
  5633. X        }
  5634. X        if(list) {
  5635. X        do_indent(indent);
  5636. X        (void)fprintf(stderr, "leaving folder \"%s\"\n", loc_name);
  5637. X        }
  5638. X    }
  5639. X    }
  5640. X}
  5641. X
  5642. Xstatic int lzh_filehdr(f)
  5643. Xstruct fileHdr *f;
  5644. X{
  5645. X    register int i;
  5646. X    char *hdr;
  5647. X    int c;
  5648. X    int ext_ptr;
  5649. X    int chk_sum = 0;
  5650. X    char *ptr;
  5651. X
  5652. X    if(in_data_size <= 0) {
  5653. X    return 0;
  5654. X    }
  5655. X    for(i = 0; i < INFOBYTES; i++) {
  5656. X    info[i] = '\0';
  5657. X    }
  5658. X    hdr = lzh_pointer;
  5659. X    in_data_size -= 2;
  5660. X    lzh_pointer += 2;
  5661. X    if(in_data_size < 0) {
  5662. X    in_data_size++;
  5663. X    }
  5664. X    f->hsize = (unsigned char)hdr[L_HSIZE];
  5665. X    if(f->hsize == 0) {
  5666. X    return 0;
  5667. X    }
  5668. X    f->hcrc = (unsigned char)hdr[L_HCRC];
  5669. X    ptr = hdr + L_METHOD;
  5670. X    in_data_size -= f->hsize;
  5671. X    lzh_pointer += f->hsize;
  5672. X    copy(&(f->method[0]), hdr + L_METHOD, 5);
  5673. X    f->psize = get4i(hdr + L_PSIZE);
  5674. X    f->upsize = get4i(hdr + L_UPSIZE);
  5675. X    f->lastmod = get4i(hdr + L_LASTMOD);
  5676. X    f->attribute = hdr[L_ATTRIBUTE + 1];
  5677. X    if(f->attribute < 2) {
  5678. X    for(i = 0; i < f->hsize; i++) {
  5679. X        chk_sum += *ptr++;
  5680. X    }
  5681. X    chk_sum &= BYTEMASK;
  5682. X    if(chk_sum != f->hcrc) {
  5683. X        (void)fprintf(stderr,
  5684. X            "Header checksum error; got %.2x, must be %.2x.\n",
  5685. X            chk_sum, f->hcrc);
  5686. X#ifdef SCAN
  5687. X        do_error("macunpack: Header checksum error");
  5688. X#endif /* SCAN */
  5689. X        exit(1);
  5690. X    }
  5691. X    f->nlength = (unsigned char)hdr[L_NLENGTH];
  5692. X    info[I_NAMEOFF] = f->nlength;
  5693. X    copy(info + I_NAMEOFF + 1, hdr + L_NAME, (int)f->nlength);
  5694. X    transname(hdr + L_NAME, text, (int)f->nlength);
  5695. X    ext_ptr = L_NLENGTH + f->nlength + 1;
  5696. X    f->crc = get2i(hdr + ext_ptr + L_CRC);
  5697. X    if(f->attribute == 1) {
  5698. X        f->etype = hdr[ext_ptr + L_ETYPE];
  5699. X        f->extendsize = hdr[ext_ptr + L_EXTENDSZ];
  5700. X        f->extend = hdr + ext_ptr + L_EXTEND;
  5701. X    } else {
  5702. X        f->extend = NULL;
  5703. X        f->extendsize = 0;
  5704. X    }
  5705. X    } else if(f->attribute == 2) {
  5706. X    in_data_size += 2;
  5707. X    lzh_pointer -= 2;
  5708. X    f->nlength = hdr[L_2EXTENDSZ] - 3;
  5709. X    info[I_NAMEOFF] = f->nlength;
  5710. X    copy(info + I_NAMEOFF + 1, hdr + L_2EXTEND + 2, (int)f->nlength);
  5711. X    transname(hdr + L_2EXTEND + 2, text, (int)f->nlength);
  5712. X    ext_ptr = 
  5713. X    f->crc = get2i(hdr + L_2CRC);
  5714. X    f->etype = hdr[L_2ETYPE];
  5715. X    ext_ptr = L_2EXTEND + 2 + f->nlength;
  5716. X    f->extendsize = hdr[ext_ptr + L_EEXTENDSZ];
  5717. X    f->extend = hdr + ext_ptr + L_EEXTEND;
  5718. X    } else {
  5719. X    (void)fprintf(stderr, "Unknown file header format (%d).\n",
  5720. X        (int)f->attribute);
  5721. X#ifdef SCAN
  5722. X    do_error("macunpack: Unknown file header format");
  5723. X#endif /* SCAN */
  5724. X    exit(1);
  5725. X    }
  5726. X    if(f->extend != NULL) {
  5727. X    if(f->extendsize > 5) {
  5728. X        f->extend += 2;
  5729. X        hdr = f->extend;
  5730. X        f->extendsize -= 3;
  5731. X        for(i = 0; i < f->extendsize; i++) {
  5732. X        c = *hdr++;
  5733. X        if((c & BYTEMASK) == BYTEMASK) {
  5734. X            hdr[-1] = ':';
  5735. X            c = ':';
  5736. X        }
  5737. X        }
  5738. X        c = *hdr++;
  5739. X        if(c == 5) {
  5740. X          hdr += 5;
  5741. X        }
  5742. X    } else {
  5743. X         if(f->extendsize == 5) {
  5744. X        hdr = f->extend;
  5745. X        f->extend = NULL;
  5746. X        f->extendsize = 0;
  5747. X        hdr += 5;
  5748. X        } else {
  5749. X        hdr = f->extend;
  5750. X        f->extend = NULL;
  5751. X        f->extendsize = 0;
  5752. X        }
  5753. X    }
  5754. X    } else {
  5755. X    hdr = hdr + ext_ptr;
  5756. X    }
  5757. X    lzh_data = hdr;
  5758. X    if(f->attribute != 0) {
  5759. X    lzh_data++;
  5760. X    }
  5761. X    return 1;
  5762. X}
  5763. X
  5764. Xstatic int lzh_checkm(f)
  5765. Xstruct fileHdr *f;
  5766. X{
  5767. X    int i, nummeth;
  5768. X    char *meth;
  5769. X
  5770. X    meth = f->method;
  5771. X    nummeth = sizeof(methods) / sizeof(struct methodinfo);
  5772. X    for(i = 0; i < nummeth; i++) {
  5773. X    if(!strncmp(methods[i].name, meth, 5)) {
  5774. X        return methods[i].number;
  5775. X    }
  5776. X    }
  5777. X    return -1;
  5778. X}
  5779. X
  5780. Xstatic char *lzh_methname(n)
  5781. Xint n;
  5782. X{
  5783. X    if(n > sizeof(methods) / sizeof(struct methodinfo)) {
  5784. X    return NULL;
  5785. X    }
  5786. X    return methods[n].name;
  5787. X}
  5788. X
  5789. Xstatic void lzh_wrfile(filehdr, method)
  5790. Xstruct fileHdr *filehdr;
  5791. Xint method;
  5792. X{
  5793. X    char ftype[5], fauth[5];
  5794. X    int rsrcLength, dataLength;
  5795. X    int doit;
  5796. X    char *mname;
  5797. X    unsigned long crc;
  5798. X
  5799. X    if(filehdr->upsize > lzh_filesize) {
  5800. X    if(lzh_filesize == 0) {
  5801. X        lzh_file = malloc((unsigned)filehdr->upsize);
  5802. X    } else {
  5803. X        lzh_file = realloc(lzh_file, (unsigned)filehdr->upsize);
  5804. X    }
  5805. X    if(lzh_file == NULL) {
  5806. X        (void)fprintf(stderr, "Insufficient memory to unpack file.\n");
  5807. X        exit(1);
  5808. X    }
  5809. X    }
  5810. X    switch(method) {
  5811. X    case lz4:
  5812. X    lzh_nocomp((unsigned long)128);
  5813. X    break;
  5814. X#ifdef UNTESTED
  5815. X    case lz5:
  5816. X    lzh_lzss1((unsigned long)128);
  5817. X    break;
  5818. X    case lzs:
  5819. X    lzh_lzss2((unsigned long)128);
  5820. X    break;
  5821. X#endif /* UNTESTED */
  5822. X    case lh0:
  5823. X    lzh_nocomp((unsigned long)128);
  5824. X    break;
  5825. X    case lh1:
  5826. X    lzh_lzah((unsigned long)128);
  5827. X    break;
  5828. X#ifdef UNDEF
  5829. X    case lh2:
  5830. X    lzh_lh2((unsigned long)128);
  5831. X    break;
  5832. X    case lh3:
  5833. X    lzh_lh3((unsigned long)128);
  5834. X    break;
  5835. X#endif /* UNDEF */
  5836. X#ifdef UNTESTED
  5837. X    case lh4:
  5838. X    lzh_lzh12((unsigned long)128);
  5839. X    break;
  5840. X#endif /* UNTESTED */
  5841. X    case lh5:
  5842. X    lzh_lzh13((unsigned long)128);
  5843. X    break;
  5844. X    default:
  5845. X    mname = lzh_methname(method);
  5846. X    if(mname != NULL) {
  5847. X        do_indent(indent);
  5848. X        (void)fprintf(stderr,
  5849. X            "\tSorry, packing method not yet implemented.\n");
  5850. X        do_indent(indent);
  5851. X        (void)fprintf(stderr, "File = \"%s\"; ", text);
  5852. X        (void)fprintf(stderr, "method = %s, skipping file.\n", mname);
  5853. X        lzh_skip(filehdr);
  5854. X        return;
  5855. X    }
  5856. X    (void)fprintf(stderr,
  5857. X        "There is something very wrong with this program!\n");
  5858. X#ifdef SCAN
  5859. X    do_error("macunpack: program error");
  5860. X#endif /* SCAN */
  5861. X    exit(1);
  5862. X    }
  5863. X    /* Checks whether everything is packed as MacBinary. */
  5864. X    if(*lzh_file != 0 /* More checks possible here. */) {
  5865. X    do_indent(indent);
  5866. X    (void)fprintf(stderr, "File = \"%s\" ", text);
  5867. X    (void)fprintf(stderr, "not packed in MacBinary, skipping file.\n");
  5868. X#ifdef SCAN
  5869. X    do_error("macunpack: not MacBinary");
  5870. X#endif /* SCAN */
  5871. X    lzh_skip(filehdr);
  5872. X    return;
  5873. X    }
  5874. X    copy(info, lzh_file, 128);
  5875. X    rsrcLength = get4(info + I_RLENOFF);
  5876. X    dataLength = get4(info + I_DLENOFF);
  5877. X    transname(info + I_TYPEOFF, ftype, 4);
  5878. X    transname(info + I_AUTHOFF, fauth, 4);
  5879. X    if(list) {
  5880. X    do_indent(indent);
  5881. X    (void)fprintf(stderr,
  5882. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  5883. X        text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  5884. X    }
  5885. X    if(info_only) {
  5886. X    doit = 0;
  5887. X    } else {
  5888. X    doit = 1;
  5889. X    }
  5890. X    if(query) {
  5891. X    doit = do_query();
  5892. X    } else if(list) {
  5893. X    (void)fputc('\n', stderr);
  5894. X    }
  5895. X    if(doit) {
  5896. X    define_name(text);
  5897. X    start_info(info, (unsigned long)rsrcLength, (unsigned long)dataLength);
  5898. X    }
  5899. X    switch(method) {
  5900. X    case lz4:
  5901. X    if(verbose) {
  5902. X        (void)fprintf(stderr, "\tNo Compression (%.5s)", filehdr->method);
  5903. X    }
  5904. X    if(doit) {
  5905. X        lzh_nocomp(filehdr->upsize);
  5906. X    }
  5907. X    break;
  5908. X#ifdef UNTESTED
  5909. X    case lz5:
  5910. X    if(verbose) {
  5911. X        (void)fprintf(stderr, "\tLZSS (%.5s) compressed (%4.1f%%)",
  5912. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5913. X    }
  5914. X    if(doit) {
  5915. X        lzh_lzss1(filehdr->upsize);
  5916. X    }
  5917. X    break;
  5918. X    case lzs:
  5919. X    if(verbose) {
  5920. X        (void)fprintf(stderr, "\tLZSS (%.5s) compressed (%4.1f%%)",
  5921. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5922. X    }
  5923. X    if(doit) {
  5924. X        lzh_lzss2(filehdr->upsize);
  5925. X    }
  5926. X    break;
  5927. X#endif /* UNTESTED */
  5928. X    case lh0:
  5929. X    if(verbose) {
  5930. X        (void)fprintf(stderr, "\tNo Compression (%.5s)", filehdr->method);
  5931. X    }
  5932. X    if(doit) {
  5933. X        lzh_nocomp(filehdr->upsize);
  5934. X    }
  5935. X    break;
  5936. X    case lh1:
  5937. X    if(verbose) {
  5938. X        (void)fprintf(stderr, "\tLZAH (%.5s) compressed (%4.1f%%)",
  5939. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5940. X    }
  5941. X    if(doit) {
  5942. X        lzh_lzah(filehdr->upsize);
  5943. X    }
  5944. X    break;
  5945. X#ifdef UNDEF
  5946. X    case lh2:
  5947. X    if(verbose) {
  5948. X        (void)fprintf(stderr, "\tLZAH (%.5s) compressed (%4.1f%%)",
  5949. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5950. X    }
  5951. X    if(doit) {
  5952. X        lzh_lh2(filehdr->upsize);
  5953. X    }
  5954. X    break;
  5955. X    case lh3:
  5956. X    if(verbose) {
  5957. X        (void)fprintf(stderr, "\tLZH (%.5s) compressed (%4.1f%%)",
  5958. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5959. X    }
  5960. X    if(doit) {
  5961. X        lzh_lzh3(filehdr->upsize);
  5962. X    }
  5963. X    break;
  5964. X#endif /* UNDEF */
  5965. X#ifdef UNTESTED
  5966. X    case lh4:
  5967. X    if(verbose) {
  5968. X        (void)fprintf(stderr, "\tLZH (%.5s) compressed (%4.1f%%)",
  5969. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5970. X    }
  5971. X    if(doit) {
  5972. X        lzh_lzh12(filehdr->upsize);
  5973. X    }
  5974. X    break;
  5975. X#endif /* UNTESTED */
  5976. X    case lh5:
  5977. X    if(verbose) {
  5978. X        (void)fprintf(stderr, "\tLZH (%.5s) compressed (%4.1f%%)",
  5979. X            filehdr->method, 100.0 * filehdr->psize / filehdr->upsize);
  5980. X    }
  5981. X    if(doit) {
  5982. X        lzh_lzh13(filehdr->upsize);
  5983. X    }
  5984. X    }
  5985. X    if(doit) {
  5986. X    crc = (*updcrc)(INIT_CRC, lzh_file, filehdr->upsize);
  5987. X    if(filehdr->crc != crc) {
  5988. X        (void)fprintf(stderr,
  5989. X            "CRC error on file: need 0x%04x, got 0x%04x\n",
  5990. X            filehdr->crc, (int)crc);
  5991. X#ifdef SCAN
  5992. X        do_error("macunpack: CRC error on file");
  5993. X#endif /* SCAN */
  5994. X        exit(1);
  5995. X    }
  5996. X    start_data();
  5997. X    copy(out_ptr, lzh_file + 128, (int)(filehdr->upsize - 128));
  5998. X    }
  5999. X    if(verbose) {
  6000. X    (void)fprintf(stderr, ".\n");
  6001. X    }
  6002. X    if(doit) {
  6003. X    end_file();
  6004. X    }
  6005. X    lzh_skip(filehdr);
  6006. X}
  6007. X
  6008. Xstatic void lzh_skip(filehdr)
  6009. Xstruct fileHdr *filehdr;
  6010. X{
  6011. X    lzh_pointer += filehdr->psize;
  6012. X    in_data_size -= filehdr->psize;
  6013. X}
  6014. X
  6015. X/*---------------------------------------------------------------------------*/
  6016. X/*    -lz4- and -lh0: No compression                         */
  6017. X/*---------------------------------------------------------------------------*/
  6018. Xstatic void lzh_nocomp(obytes)
  6019. Xunsigned long obytes;
  6020. X{
  6021. X    copy(lzh_file, lzh_data, (int)obytes);
  6022. X}
  6023. X
  6024. X#ifdef UNTESTED
  6025. X/*---------------------------------------------------------------------------*/
  6026. X/*    -lz5-: LZSS compression, variant 1                     */
  6027. X/*---------------------------------------------------------------------------*/
  6028. Xstatic void lzh_lzss1(obytes)
  6029. Xunsigned long obytes;
  6030. X{
  6031. X    int mask, ch, lzcnt, lzptr, ptr, count;
  6032. X    char *p = lzh_lzbuf;
  6033. X    int i, j;
  6034. X
  6035. X    for(i = 0; i < 256; i++) {
  6036. X    for(j = 0; j < 13; j++) {
  6037. X        *p++ = i;
  6038. X    }
  6039. X    }
  6040. X    for(i = 0; i < 256; i++) {
  6041. X    *p++ = i;
  6042. X    }
  6043. X    for(i = 0; i < 256; i++) {
  6044. X    *p++ = 255 - i;
  6045. X    }
  6046. X    for(i = 0; i < 128; i++) {
  6047. X    *p++ = 0;
  6048. X    }
  6049. X    for(i = 0; i < 128; i++) {
  6050. X    *p++ = ' ';
  6051. X    }
  6052. X
  6053. X    tmp_out_ptr = out_ptr;
  6054. X    out_ptr = lzh_file;
  6055. X    ptr = LZ5BUFFSIZE - LZ5LOOKAHEAD;
  6056. X    count = 0;
  6057. X    lzh_current = lzh_data;
  6058. X    while(obytes != 0) {
  6059. X    if(count == 0) {
  6060. X        mask = *lzh_current++ & BYTEMASK;
  6061. X        count = 8;
  6062. X    }
  6063. X    count--;
  6064. X    ch = *lzh_current++ & BYTEMASK;
  6065. X    if ((mask & 1) != 0) {
  6066. X        *out_ptr++ = ch;
  6067. X        lzh_lzbuf[ptr++] = ch;
  6068. X        ptr &= LZ5MASK;
  6069. X        obytes--;
  6070. X    } else {
  6071. X        lzcnt = *lzh_current++;
  6072. X        lzptr = (ch & 0x00ff) | ((lzcnt << 4) & 0x0f00);
  6073. X        lzcnt = (lzcnt & 0x000f) + 3;
  6074. X        obytes -= lzcnt;
  6075. X        do {
  6076. X        ch = lzh_lzbuf[lzptr++];
  6077. X        lzh_lzbuf[ptr++] = ch;
  6078. X        *out_ptr++ = ch;
  6079. X        lzptr &= LZ5MASK;
  6080. X        ptr &= LZ5MASK;
  6081. X        } while (--lzcnt != 0) ;
  6082. X    }
  6083. X    mask >>= 1;
  6084. X    }
  6085. X    out_ptr = tmp_out_ptr;
  6086. X}
  6087. X
  6088. X/*---------------------------------------------------------------------------*/
  6089. X/*    -lzs-: LZSS compression, variant 2                     */
  6090. X/*---------------------------------------------------------------------------*/
  6091. Xstatic void lzh_lzss2(obytes)
  6092. Xunsigned long obytes;
  6093. X{
  6094. X    int ch, lzcnt, lzptr, ptr, i;
  6095. X
  6096. X    tmp_out_ptr = out_ptr;
  6097. X    out_ptr = lzh_file;
  6098. X    ptr = LZSBUFFSIZE - LZSLOOKAHEAD;
  6099. X    for(i = 0; i < ptr; i++) {
  6100. X    lzh_lzbuf[i] = ' ';
  6101. X    }
  6102. X    for(i = ptr; i < LZSBUFFSIZE; i++) {
  6103. X    lzh_lzbuf[i] = 0;
  6104. X    }
  6105. X    bit_be_init_getbits();
  6106. X    bit_be_filestart = lzh_data;
  6107. X    bit_be_inbytes = -1;
  6108. X    while(obytes != 0) {
  6109. X    if(bit_be_getbits(1) == 0) {
  6110. X        ch = bit_be_getbits(8);
  6111. X        *out_ptr++ = ch;
  6112. X        lzh_lzbuf[ptr++] = ch;
  6113. X        ptr &= LZSMASK;
  6114. X        obytes--;
  6115. X    } else {
  6116. X        lzptr = bit_be_getbits(11);
  6117. X        lzcnt = bit_be_getbits(4) + 3;
  6118. X        obytes -= lzcnt;
  6119. X        do {
  6120. X        ch = lzh_lzbuf[lzptr++];
  6121. X        lzh_lzbuf[ptr++] = ch;
  6122. X        *out_ptr++ = ch;
  6123. X        lzptr &= LZSMASK;
  6124. X        ptr &= LZSMASK;
  6125. X        } while (--lzcnt != 0) ;
  6126. X    }
  6127. X    }
  6128. X    out_ptr = tmp_out_ptr;
  6129. X}
  6130. X#endif /* UNTESTED */
  6131. X
  6132. X/*---------------------------------------------------------------------------*/
  6133. X/*    -lh1-: LZ compression plus adaptive Huffman encoding             */
  6134. X/*---------------------------------------------------------------------------*/
  6135. Xstatic void lzh_lzah(obytes)
  6136. Xunsigned long obytes;
  6137. X{
  6138. X    lzh_current = lzh_data + 2; /* SKIPPING BLOCKSIZE! */
  6139. X    tmp_out_ptr = out_ptr;
  6140. X    out_ptr = lzh_file;
  6141. X    lzah_getbyte = lzh_getbyte;
  6142. X    de_lzah(obytes);
  6143. X    out_ptr = tmp_out_ptr;
  6144. X}
  6145. X
  6146. Xstatic unsigned char lzh_getbyte()
  6147. X{
  6148. X    return *lzh_current++;
  6149. X}
  6150. X
  6151. X#ifdef UNDEF
  6152. X/*---------------------------------------------------------------------------*/
  6153. X/*    -lh2-: LZ** compression                             */
  6154. X/*---------------------------------------------------------------------------*/
  6155. Xstatic void lzh_lh2(obytes)
  6156. Xunsigned long obytes;
  6157. X{
  6158. X}
  6159. X
  6160. X/*---------------------------------------------------------------------------*/
  6161. X/*    -lh3-: LZ** compression                             */
  6162. X/*---------------------------------------------------------------------------*/
  6163. Xstatic void lzh_lh3(obytes)
  6164. Xunsigned long obytes;
  6165. X{
  6166. X}
  6167. X#endif /* UNDEF */
  6168. X
  6169. X#ifdef UNTESTED
  6170. X/*---------------------------------------------------------------------------*/
  6171. X/*    -lh4-: LZ(12) compression plus Huffman encoding                 */
  6172. X/*---------------------------------------------------------------------------*/
  6173. Xstatic void lzh_lzh12(obytes)
  6174. Xunsigned long obytes;
  6175. X{
  6176. X    lzh_current = lzh_data;
  6177. X    tmp_out_ptr = out_ptr;
  6178. X    out_ptr = lzh_file;
  6179. X    /* Controlled by obytes only */
  6180. X    de_lzh((long)(-1), (long)obytes, &lzh_current, 12);
  6181. X    out_ptr = tmp_out_ptr;
  6182. X}
  6183. X#endif /* UNTESTED */
  6184. X
  6185. X/*---------------------------------------------------------------------------*/
  6186. X/*    -lh5-: LZ(13) compression plus Huffman encoding                 */
  6187. X/*---------------------------------------------------------------------------*/
  6188. Xstatic void lzh_lzh13(obytes)
  6189. Xunsigned long obytes;
  6190. X{
  6191. X    lzh_current = lzh_data;
  6192. X    tmp_out_ptr = out_ptr;
  6193. X    out_ptr = lzh_file;
  6194. X    /* Controlled by obytes only */
  6195. X    de_lzh((long)(-1), (long)obytes, &lzh_current, 13);
  6196. X    out_ptr = tmp_out_ptr;
  6197. X}
  6198. X#else /* LZH */
  6199. Xint lzh; /* keep lint and some compilers happy */
  6200. X#endif /* LZH */
  6201. X
  6202. SHAR_EOF
  6203. if test 18707 -ne "`wc -c < 'lzh.c'`"
  6204. then
  6205.     echo shar: "error transmitting 'lzh.c'" '(should have been 18707 characters)'
  6206. fi
  6207. fi
  6208. echo shar: "extracting 'lzc.c'" '(4405 characters)'
  6209. if test -f 'lzc.c'
  6210. then
  6211.     echo shar: "will not over-write existing file 'lzc.c'"
  6212. else
  6213. sed 's/^X//' << \SHAR_EOF > 'lzc.c'
  6214. X#include "macunpack.h"
  6215. X#ifdef LZC
  6216. X#include "globals.h"
  6217. X#include "lzc.h"
  6218. X#include "../util/util.h"
  6219. X#include "../fileio/machdr.h"
  6220. X#include "../fileio/wrfile.h"
  6221. X#include "../util/masks.h"
  6222. X
  6223. Xextern void de_compress();
  6224. Xextern void core_compress();
  6225. Xextern void mcb();
  6226. X
  6227. Xstatic void lzc_zivm();
  6228. Xstatic void lzc_wrfile();
  6229. Xstatic void lzc_zivu();
  6230. X
  6231. Xvoid lzc(ohdr)
  6232. Xchar *ohdr;
  6233. X{
  6234. X    core_compress((char *)NULL);
  6235. X    if(!strncmp(ohdr + I_TYPEOFF, "ZIVM", 4)) {
  6236. X    lzc_zivm(ohdr);
  6237. X    } else {
  6238. X    lzc_zivu(ohdr);
  6239. X    }
  6240. X}
  6241. X
  6242. Xstatic void lzc_zivm(ohdr)
  6243. Xchar *ohdr;
  6244. X{
  6245. X    char hdr[HEADERBYTES];
  6246. X    unsigned long dataLength, rsrcLength, dataCLength, rsrcCLength;
  6247. X    char ftype[5], fauth[5];
  6248. X
  6249. X    if(fread(hdr, 1, HEADERBYTES, infp) != HEADERBYTES) {
  6250. X    (void)fprintf(stderr, "Can't read file header\n");
  6251. X#ifdef SCAN
  6252. X    do_error("macunpack: Can't read file header");
  6253. X#endif /* SCAN */
  6254. X    exit(1);
  6255. X    }
  6256. X    if(strncmp(hdr, MAGIC1, 4)) {
  6257. X    (void)fprintf(stderr, "Magic header mismatch\n");
  6258. X#ifdef SCAN
  6259. X    do_error("macunpack: Magic header mismatch");
  6260. X#endif /* SCAN */
  6261. X    exit(1);
  6262. X    }
  6263. X    dataLength = get4(hdr + C_DLENOFF);
  6264. X    dataCLength = get4(hdr + C_DLENOFFC);
  6265. X    rsrcLength = get4(hdr + C_RLENOFF);
  6266. X    rsrcCLength = get4(hdr + C_RLENOFFC);
  6267. X
  6268. X    write_it = 1;
  6269. X    if(list) {
  6270. X    copy(info, ohdr, INFOBYTES);
  6271. X    copy(info + I_TYPEOFF, hdr + C_TYPEOFF, 4);
  6272. X    copy(info + I_AUTHOFF, hdr + C_AUTHOFF, 4);
  6273. X    copy(info + I_DLENOFF, hdr + C_DLENOFF, 4);
  6274. X    copy(info + I_RLENOFF, hdr + C_RLENOFF, 4);
  6275. X    copy(info + I_CTIMOFF, hdr + C_CTIMOFF, 4);
  6276. X    copy(info + I_MTIMOFF, hdr + C_MTIMOFF, 4);
  6277. X    copy(info + I_FLAGOFF, hdr + C_FLAGOFF, 8);
  6278. X
  6279. X    transname(ohdr + I_NAMEOFF + 1, text, (int)ohdr[I_NAMEOFF]);
  6280. X    transname(hdr + C_TYPEOFF, ftype, 4);
  6281. X    transname(hdr + C_AUTHOFF, fauth, 4);
  6282. X    do_indent(indent);
  6283. X    (void)fprintf(stderr,
  6284. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  6285. X        text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  6286. X    if(info_only) {
  6287. X        write_it = 0;
  6288. X    }
  6289. X    if(query) {
  6290. X        write_it = do_query();
  6291. X    } else {
  6292. X        (void)fputc('\n', stderr);
  6293. X    }
  6294. X    }
  6295. X
  6296. X    if(write_it) {
  6297. X    define_name(text);
  6298. X    }
  6299. X    if(write_it) {
  6300. X    start_info(info, rsrcLength, dataLength);
  6301. X    }
  6302. X    if(verbose) {
  6303. X    (void)fprintf(stderr, "\tData: ");
  6304. X    }
  6305. X    if(write_it) {
  6306. X    start_data();
  6307. X    }
  6308. X    lzc_wrfile(dataLength, dataCLength);
  6309. X    if(verbose) {
  6310. X    (void)fprintf(stderr, ", Rsrc: ");
  6311. X    }
  6312. X    if(write_it) {
  6313. X    start_rsrc();
  6314. X    }
  6315. X    lzc_wrfile(rsrcLength, rsrcCLength);
  6316. X    if(write_it) {
  6317. X    end_file();
  6318. X    }
  6319. X    if(verbose) {
  6320. X    (void)fprintf(stderr, ".\n");
  6321. X    }
  6322. X}
  6323. X
  6324. Xstatic void lzc_wrfile(obytes, ibytes)
  6325. Xunsigned long obytes, ibytes;
  6326. X{
  6327. X    int n, nbits;
  6328. X    char subheader[3];
  6329. X
  6330. X    if(ibytes == 0) {
  6331. X    if(verbose) {
  6332. X        (void)fprintf(stderr, "empty");
  6333. X    }
  6334. X    return;
  6335. X    }
  6336. X    if(ibytes == obytes) {
  6337. X    if(verbose) {
  6338. X        (void)fprintf(stderr, "No compression");
  6339. X    }
  6340. X    if(write_it) {
  6341. X        n = fread(out_buffer, 1, (int)ibytes, infp);
  6342. X        if(n != ibytes) {
  6343. X        (void)fprintf(stderr, "Premature EOF\n");
  6344. X#ifdef SCAN
  6345. X        do_error("macunpack: Premature EOF");
  6346. X#endif /* SCAN */
  6347. X        exit(1);
  6348. X        }
  6349. X    } else {
  6350. X        n = ibytes;
  6351. X        while(n-- > 0) {
  6352. X        if(getc(infp) == EOF) {
  6353. X            (void)fprintf(stderr, "Premature EOF\n");
  6354. X#ifdef SCAN
  6355. X            do_error("macunpack: Premature EOF");
  6356. X#endif /* SCAN */
  6357. X            exit(1);
  6358. X        }
  6359. X        }
  6360. X    }
  6361. X    } else {
  6362. X    if(fread(subheader, 1, 3, infp) != 3) {
  6363. X        (void)fprintf(stderr, "Premature EOF\n");
  6364. X#ifdef SCAN
  6365. X        do_error("macunpack: Premature EOF");
  6366. X#endif /* SCAN */
  6367. X        exit(1);
  6368. X    }
  6369. X    if(strncmp(subheader, MAGIC2, 2)) {
  6370. X        (void)fprintf(stderr, "Magic subheader mismatch\n");
  6371. X#ifdef SCAN
  6372. X        do_error("macunpack: Magic subheader mismatch");
  6373. X#endif /* SCAN */
  6374. X        exit(1);
  6375. X    }
  6376. X    nbits = subheader[2] & 0x7f;
  6377. X    if(verbose) {
  6378. X        (void)fprintf(stderr, "LZC(%d) compressed (%4.1f%%)",
  6379. X            nbits, 100.0 * ibytes / obytes);
  6380. X    }
  6381. X    if(write_it) {
  6382. X        de_compress(ibytes - 3, nbits);
  6383. X    } else {
  6384. X        n = ibytes - 3;
  6385. X        while(n-- > 0) {
  6386. X        if(getc(infp) == EOF) {
  6387. X            (void)fprintf(stderr, "Premature EOF\n");
  6388. X#ifdef SCAN
  6389. X            do_error("macunpack: Premature EOF");
  6390. X#endif /* SCAN */
  6391. X            exit(1);
  6392. X        }
  6393. X        }
  6394. X    }
  6395. X    }
  6396. X}
  6397. X
  6398. Xstatic void lzc_zivu(ohdr)
  6399. Xchar *ohdr;
  6400. X{
  6401. X    (void)fprintf(stderr,
  6402. X        "\tMacCompress(Unix) not yet implemented, copied as MacBinary\n");
  6403. X    mcb(ohdr, (unsigned long)in_rsrc_size, (unsigned long)in_data_size,
  6404. X    in_ds + in_rs);
  6405. X}
  6406. X#else /* LZC */
  6407. Xint lzc; /* keep lint and some compilers happy */
  6408. X#endif /* LZC */
  6409. X
  6410. SHAR_EOF
  6411. if test 4405 -ne "`wc -c < 'lzc.c'`"
  6412. then
  6413.     echo shar: "error transmitting 'lzc.c'" '(should have been 4405 characters)'
  6414. fi
  6415. fi
  6416. echo shar: "extracting 'macbinary.c'" '(13547 characters)'
  6417. if test -f 'macbinary.c'
  6418. then
  6419.     echo shar: "will not over-write existing file 'macbinary.c'"
  6420. else
  6421. sed 's/^X//' << \SHAR_EOF > 'macbinary.c'
  6422. X#include "macunpack.h"
  6423. X#include "globals.h"
  6424. X#include "../fileio/machdr.h"
  6425. X#include "../fileio/wrfile.h"
  6426. X#include "../fileio/kind.h"
  6427. X#include "zmahdr.h"
  6428. X#include "../util/util.h"
  6429. X
  6430. Xextern void dir();
  6431. Xextern void mcb();
  6432. X#ifdef BIN
  6433. Xextern void bin();
  6434. X#endif /* BIN */
  6435. X#ifdef JDW
  6436. Xextern void jdw();
  6437. X#endif /* JDW */
  6438. X#ifdef STF
  6439. Xextern void stf();
  6440. X#endif /* STF */
  6441. X#ifdef LZC
  6442. Xextern void lzc();
  6443. X#endif /* LZC */
  6444. X#ifdef ASQ
  6445. Xextern void asq();
  6446. X#endif /* ASQ */
  6447. X#ifdef ARC
  6448. Xextern void arc();
  6449. X#endif /* ARC */
  6450. X#ifdef PIT
  6451. Xextern void pit();
  6452. X#endif /* PIT */
  6453. X#ifdef SIT
  6454. Xextern void sit();
  6455. X#endif /* SIT */
  6456. X#ifdef DIA
  6457. Xextern void dia();
  6458. X#endif /* DIA */
  6459. X#ifdef CPT
  6460. Xextern void cpt();
  6461. X#endif /* CPT */
  6462. X#ifdef ZMA
  6463. Xextern void zma();
  6464. X#endif /* ZMA */
  6465. X#ifdef LZH
  6466. Xextern void lzh();
  6467. X#endif /* LZH */
  6468. X#ifdef DD
  6469. Xextern void dd_file();
  6470. Xextern void dd_arch();
  6471. X#endif /* DD */
  6472. X
  6473. Xstatic void skip_file();
  6474. X#ifdef SCAN
  6475. Xstatic void get_idf();
  6476. X#endif /* SCAN */
  6477. X
  6478. X#define Z    (ZMAHDRS2 + 1)
  6479. X
  6480. Xstatic int info_given;
  6481. X
  6482. Xvoid macbinary()
  6483. X{
  6484. X    char header[INFOBYTES];
  6485. X    int c;
  6486. X
  6487. X    while(1) {
  6488. X    if((c = fgetc(infp)) == EOF) {
  6489. X        break;
  6490. X    }
  6491. X    (void)ungetc(c, infp);
  6492. X    if(fread(header, 1, Z, infp) != Z) {
  6493. X        (void)fprintf(stderr, "Can't read MacBinary header.\n");
  6494. X#ifdef SCAN
  6495. X        do_error("macunpack: Can't read MacBinary header");
  6496. X#endif /* SCAN */
  6497. X        exit(1);
  6498. X    }
  6499. X#ifdef ZMA
  6500. X    if(!strncmp(header + 1, ZMAHDR, ZMAHDRS2)) {
  6501. X        /* Can distinguish zoom data forks only this way from macbinary */
  6502. X        if(verbose) {
  6503. X        (void)fprintf(stderr, "This is a \"Zoom\" archive.\n");
  6504. X        }
  6505. X        zma(header, (unsigned long)0);
  6506. X        exit(0);
  6507. X    }
  6508. X#endif /* ZMA */
  6509. X    if(fread(header + Z, 1, INFOBYTES - Z, infp) != INFOBYTES - Z) {
  6510. X        (void)fprintf(stderr, "Can't read MacBinary header.\n");
  6511. X#ifdef SCAN
  6512. X        do_error("macunpack: Can't read MacBinary header");
  6513. X#endif /* SCAN */
  6514. X        exit(1);
  6515. X    }
  6516. X    if(verbose && !info_given) {
  6517. X        do_indent(indent);
  6518. X        (void)fprintf(stderr, "This is \"MacBinary\" input.\n");
  6519. X        info_given = 1;
  6520. X    }
  6521. X    if(header[I_NAMEOFF] & 0x80) {
  6522. X        dir(header);
  6523. X        continue;
  6524. X    }
  6525. X    in_data_size = get4(header + I_DLENOFF);
  6526. X    in_rsrc_size = get4(header + I_RLENOFF);
  6527. X    in_ds = (((in_data_size + 127) >> 7) << 7);
  6528. X    in_rs = (((in_rsrc_size + 127) >> 7) << 7);
  6529. X    ds_skip = in_ds - in_data_size;
  6530. X    rs_skip = in_rs - in_rsrc_size;
  6531. X    if(dir_skip != 0) {
  6532. X        skip_file(in_ds + in_rs);
  6533. X        continue;
  6534. X    }
  6535. X#ifdef SCAN
  6536. X    if(header[I_NAMEOFF] == 0) {
  6537. X        get_idf((int)header[I_NAMEOFF + 1]);
  6538. X        skip_file(ds_skip + in_rs);
  6539. X        continue;
  6540. X    }
  6541. X#endif /* SCAN */
  6542. X    header[I_NAMEOFF + 1 + header[I_NAMEOFF]] = 0;
  6543. X#ifdef BIN
  6544. X    if(!strncmp(header + I_TYPEOFF, "TEXT", 4) &&
  6545. X       !strncmp(header + I_AUTHOFF, "BnHq", 4)) {
  6546. X        if(verbose) {
  6547. X        do_indent(indent);
  6548. X        (void)fprintf(stderr,
  6549. X            "This is a \"BinHex 5.0\" packed file.\n");
  6550. X        }
  6551. X#ifdef SCAN
  6552. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6553. X#endif /* SCAN */
  6554. X        bin(header, in_data_size, 0);
  6555. X        skip_file(ds_skip + in_rs);
  6556. X        continue;
  6557. X    }
  6558. X    if(!strncmp(header + I_TYPEOFF, "TEXT", 4) &&
  6559. X       !strncmp(header + I_AUTHOFF, "GJBU", 4)) {
  6560. X        if(verbose) {
  6561. X        do_indent(indent);
  6562. X        (void)fprintf(stderr,
  6563. X            "This is a \"MacBinary 1.0\" packed file.\n");
  6564. X        }
  6565. X#ifdef SCAN
  6566. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6567. X#endif /* SCAN */
  6568. X        bin(header, in_data_size, 0);
  6569. X        skip_file(ds_skip + in_rs);
  6570. X        continue;
  6571. X    }
  6572. X    /* Recognize only if creator is UMcp.  UMCP uses ttxt as default. */
  6573. X    if(!strncmp(header + I_TYPEOFF, "TEXT", 4) &&
  6574. X       !strncmp(header + I_AUTHOFF, "UMcp", 4)) {
  6575. X        if(verbose) {
  6576. X        do_indent(indent);
  6577. X        (void)fprintf(stderr, "This is a \"UMCP\" packed file.\n");
  6578. X        }
  6579. X#ifdef SCAN
  6580. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6581. X#endif /* SCAN */
  6582. X        bin(header, in_data_size, 1);
  6583. X        skip_file(ds_skip + in_rs);
  6584. X        continue;
  6585. X    }
  6586. X#endif /* BIN */
  6587. X#ifdef JDW
  6588. X    if(!strncmp(header + I_TYPEOFF, "Smal", 4) &&
  6589. X       !strncmp(header + I_AUTHOFF, "Jdw ", 4)) {
  6590. X        if(verbose) {
  6591. X        do_indent(indent);
  6592. X        (void)fprintf(stderr,
  6593. X            "This is a \"Compress It\" compressed file.\n");
  6594. X        }
  6595. X#ifdef SCAN
  6596. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6597. X#endif /* SCAN */
  6598. X        jdw((unsigned long)in_data_size);
  6599. X        skip_file(ds_skip + in_rs);
  6600. X        continue;
  6601. X    }
  6602. X#endif /* JDW */
  6603. X#ifdef STF
  6604. X    if(!strncmp(header + I_TYPEOFF, "COMP", 4) &&
  6605. X       !strncmp(header + I_AUTHOFF, "STF ", 4)) {
  6606. X        if(verbose) {
  6607. X        do_indent(indent);
  6608. X        (void)fprintf(stderr,
  6609. X            "This is a \"ShrinkToFit\" compressed file.\n");
  6610. X        }
  6611. X#ifdef SCAN
  6612. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6613. X#endif /* SCAN */
  6614. X        stf((unsigned long)in_data_size);
  6615. X        skip_file(ds_skip + in_rs);
  6616. X        continue;
  6617. X    }
  6618. X#endif /* STF */
  6619. X#ifdef LZC
  6620. X    if(!strncmp(header + I_TYPEOFF, "ZIVM", 4) &&
  6621. X       !strncmp(header + I_AUTHOFF, "LZIV", 4)) {
  6622. X        if(verbose) {
  6623. X        do_indent(indent);
  6624. X        (void)fprintf(stderr,
  6625. X            "This is a \"MacCompress(M)\" compressed file.\n");
  6626. X        }
  6627. X#ifdef SCAN
  6628. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6629. X#endif /* SCAN */
  6630. X        lzc(header);
  6631. X        skip_file(ds_skip + in_rs);
  6632. X        continue;
  6633. X    }
  6634. X    if(!strncmp(header + I_TYPEOFF, "ZIVU", 4) &&
  6635. X       !strncmp(header + I_AUTHOFF, "LZIV", 4)) {
  6636. X        if(verbose) {
  6637. X        do_indent(indent);
  6638. X        (void)fprintf(stderr,
  6639. X            "This is a \"MacCompress(U)\" compressed file.\n");
  6640. X        }
  6641. X#ifdef SCAN
  6642. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6643. X#endif /* SCAN */
  6644. X        lzc(header);
  6645. X        continue;
  6646. X    }
  6647. X#endif /* LZC */
  6648. X#ifdef ASQ
  6649. X    if(!strncmp(header + I_TYPEOFF, "ArCv", 4) &&
  6650. X       !strncmp(header + I_AUTHOFF, "TrAS", 4)) {
  6651. X        if(verbose) {
  6652. X        do_indent(indent);
  6653. X        (void)fprintf(stderr,
  6654. X            "This is a \"AutoSqueeze\" compressed file.\n");
  6655. X        }
  6656. X#ifdef SCAN
  6657. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6658. X#endif /* SCAN */
  6659. X        lzh(0);
  6660. X        skip_file(ds_skip + in_rs);
  6661. X        continue;
  6662. X    }
  6663. X#endif /* ASQ */
  6664. X#ifdef ARC
  6665. X    if(!strncmp(header + I_TYPEOFF, "mArc", 4) &&
  6666. X       !strncmp(header + I_AUTHOFF, "arc*", 4)) {
  6667. X        if(verbose) {
  6668. X        do_indent(indent);
  6669. X        (void)fprintf(stderr, "This is a \"ArcMac\" archive.\n");
  6670. X        }
  6671. X#ifdef SCAN
  6672. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6673. X#endif /* SCAN */
  6674. X        arc();
  6675. X        skip_file(ds_skip + in_rs);
  6676. X        continue;
  6677. X    }
  6678. X    if(!strncmp(header + I_TYPEOFF, "APPL", 4) &&
  6679. X       !strncmp(header + I_AUTHOFF, "arc@", 4)) {
  6680. X        if(verbose) {
  6681. X        do_indent(indent);
  6682. X        (void)fprintf(stderr,
  6683. X            "This is a \"ArcMac\" self extracting archive.\n");
  6684. X        }
  6685. X#ifdef SCAN
  6686. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6687. X#endif /* SCAN */
  6688. X        arc();
  6689. X        skip_file(ds_skip + in_rs);
  6690. X        continue;
  6691. X    }
  6692. X#endif /* ARC */
  6693. X#ifdef PIT
  6694. X    if(!strncmp(header + I_TYPEOFF, "PIT ", 4) &&
  6695. X       !strncmp(header + I_AUTHOFF, "PIT ", 4)) {
  6696. X        if(verbose) {
  6697. X        do_indent(indent);
  6698. X        (void)fprintf(stderr, "This is a \"PackIt\" archive.\n");
  6699. X        }
  6700. X#ifdef SCAN
  6701. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6702. X#endif /* SCAN */
  6703. X        pit();
  6704. X        skip_file(ds_skip + in_rs);
  6705. X        continue;
  6706. X    }
  6707. X#endif /* PIT */
  6708. X#ifdef SIT
  6709. X    if(!strncmp(header + I_TYPEOFF, "SIT!", 4) &&
  6710. X       !strncmp(header + I_AUTHOFF, "SIT!", 4)) {
  6711. X        if(verbose) {
  6712. X        do_indent(indent);
  6713. X        (void)fprintf(stderr, "This is a \"StuffIt\" archive.\n");
  6714. X        }
  6715. X#ifdef SCAN
  6716. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6717. X#endif /* SCAN */
  6718. X        sit();
  6719. X        skip_file(ds_skip + in_rs);
  6720. X        continue;
  6721. X    }
  6722. X    if(!strncmp(header + I_TYPEOFF, "SITD", 4) &&
  6723. X       !strncmp(header + I_AUTHOFF, "SIT!", 4)) {
  6724. X        if(verbose) {
  6725. X        do_indent(indent);
  6726. X        (void)fprintf(stderr,
  6727. X            "This is a \"StuffIt Deluxe\" archive.\n");
  6728. X        }
  6729. X#ifdef SCAN
  6730. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6731. X#endif /* SCAN */
  6732. X        sit();
  6733. X        skip_file(ds_skip + in_rs);
  6734. X        continue;
  6735. X    }
  6736. X    if(!strncmp(header + I_TYPEOFF, "APPL", 4) &&
  6737. X       !strncmp(header + I_AUTHOFF, "aust", 4)) {
  6738. X        if(verbose) {
  6739. X        do_indent(indent);
  6740. X        (void)fprintf(stderr,
  6741. X            "This is a \"StuffIt\" self extracting archive.\n");
  6742. X        }
  6743. X#ifdef SCAN
  6744. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6745. X#endif /* SCAN */
  6746. X        sit();
  6747. X        skip_file(ds_skip + in_rs);
  6748. X        continue;
  6749. X    }
  6750. X#endif /* SIT */
  6751. X#ifdef DIA
  6752. X    if(!strncmp(header + I_TYPEOFF, "Pack", 4) &&
  6753. X       !strncmp(header + I_AUTHOFF, "Pack", 4)) {
  6754. X        if(verbose) {
  6755. X        do_indent(indent);
  6756. X        (void)fprintf(stderr, "This is a \"Diamond\" archive.\n");
  6757. X        }
  6758. X#ifdef SCAN
  6759. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6760. X#endif /* SCAN */
  6761. X        dia((unsigned char *)header);
  6762. X        skip_file(ds_skip + in_rs);
  6763. X        continue;
  6764. X    }
  6765. X    if(!strncmp(header + I_TYPEOFF, "APPL", 4) &&
  6766. X       !strncmp(header + I_AUTHOFF, "Pack", 4) &&
  6767. X       in_data_size != 0) {
  6768. X        if(verbose) {
  6769. X        do_indent(indent);
  6770. X        (void)fprintf(stderr,
  6771. X            "This is a \"Diamond\" self extracting archive.\n");
  6772. X        }
  6773. X#ifdef SCAN
  6774. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6775. X#endif /* SCAN */
  6776. X        dia((unsigned char *)header);
  6777. X        skip_file(ds_skip + in_rs);
  6778. X        continue;
  6779. X    }
  6780. X#endif /* DIA */
  6781. X#ifdef CPT
  6782. X    if(!strncmp(header + I_TYPEOFF, "PACT", 4) &&
  6783. X       !strncmp(header + I_AUTHOFF, "CPCT", 4)) {
  6784. X        if(verbose) {
  6785. X        do_indent(indent);
  6786. X        (void)fprintf(stderr, "This is a \"Compactor\" archive.\n");
  6787. X        }
  6788. X#ifdef SCAN
  6789. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6790. X#endif /* SCAN */
  6791. X        cpt();
  6792. X        skip_file(ds_skip + in_rs);
  6793. X        continue;
  6794. X    }
  6795. X    if(!strncmp(header + I_TYPEOFF, "APPL", 4) &&
  6796. X       !strncmp(header + I_AUTHOFF, "EXTR", 4)) {
  6797. X        if(verbose) {
  6798. X        do_indent(indent);
  6799. X        (void)fprintf(stderr,
  6800. X            "This is a \"Compactor\" self extracting archive.\n");
  6801. X        }
  6802. X#ifdef SCAN
  6803. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6804. X#endif /* SCAN */
  6805. X        cpt();
  6806. X        skip_file(ds_skip + in_rs);
  6807. X        continue;
  6808. X    }
  6809. X#endif /* CPT */
  6810. X#ifdef ZMA
  6811. X    if(!strncmp(header + I_TYPEOFF, "zooM", 4) &&
  6812. X       !strncmp(header + I_AUTHOFF, "zooM", 4)) {
  6813. X        if(verbose) {
  6814. X        do_indent(indent);
  6815. X        (void)fprintf(stderr, "This is a \"Zoom\" archive.\n");
  6816. X        }
  6817. X#ifdef SCAN
  6818. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6819. X#endif /* SCAN */
  6820. X        zma((char *)NULL, (unsigned long)in_data_size);
  6821. X        skip_file(ds_skip + in_rs);
  6822. X        continue;
  6823. X    }
  6824. X    if(!strncmp(header + I_TYPEOFF, "APPL", 4) &&
  6825. X       !strncmp(header + I_AUTHOFF, "Mooz", 4)) {
  6826. X        if(verbose) {
  6827. X        do_indent(indent);
  6828. X        (void)fprintf(stderr,
  6829. X            "This is a \"Zoom\" self extracting archive.\n");
  6830. X        }
  6831. X#ifdef SCAN
  6832. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6833. X#endif /* SCAN */
  6834. X        zma((char *)NULL, (unsigned long)in_data_size);
  6835. X        skip_file(ds_skip + in_rs);
  6836. X        continue;
  6837. X    }
  6838. X#endif /* ZMA */
  6839. X#ifdef LZH
  6840. X    if(!strncmp(header + I_TYPEOFF, "LARC", 4) &&
  6841. X       !strncmp(header + I_AUTHOFF, "LARC", 4)) {
  6842. X        if(verbose) {
  6843. X        do_indent(indent);
  6844. X        (void)fprintf(stderr,
  6845. X            "This is a \"MacLHa (LHARC)\" archive.\n");
  6846. X        }
  6847. X#ifdef SCAN
  6848. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6849. X#endif /* SCAN */
  6850. X        lzh(0);
  6851. X        skip_file(ds_skip + in_rs);
  6852. X        continue;
  6853. X    }
  6854. X    if(!strncmp(header + I_TYPEOFF, "LHA ", 4) &&
  6855. X       !strncmp(header + I_AUTHOFF, "LARC", 4)) {
  6856. X        if(verbose) {
  6857. X        do_indent(indent);
  6858. X        (void)fprintf(stderr,
  6859. X            "This is a \"MacLHa (LHA)\" archive.\n");
  6860. X        }
  6861. X#ifdef SCAN
  6862. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6863. X#endif /* SCAN */
  6864. X        lzh(1);
  6865. X        skip_file(ds_skip + in_rs);
  6866. X        continue;
  6867. X    }
  6868. X#endif /* LZH */
  6869. X#ifdef DD
  6870. X    if((!strncmp(header + I_TYPEOFF, "DD01", 4) ||
  6871. X        !strncmp(header + I_TYPEOFF, "DDF?", 3) ||
  6872. X        !strncmp(header + I_TYPEOFF, "DDf?", 3)) &&
  6873. X       !strncmp(header + I_AUTHOFF, "DDAP", 4)) {
  6874. X        if(verbose) {
  6875. X        do_indent(indent);
  6876. X        (void)fprintf(stderr,
  6877. X            "This is a \"DiskDoubler\" compressed file.\n");
  6878. X        }
  6879. X#ifdef SCAN
  6880. X        do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6881. X#endif /* SCAN */
  6882. X        dd_file((unsigned char *)header);
  6883. X        skip_file(ds_skip + in_rs);
  6884. X        continue;
  6885. X    }
  6886. X    if(!strncmp(header + I_TYPEOFF, "DDAR", 4) &&
  6887. X       !strncmp(header + I_AUTHOFF, "DDAP", 4)) {
  6888. X        if(verbose) {
  6889. X        do_indent(indent);
  6890. X        (void)fprintf(stderr, "This is a \"DiskDoubler\" archive.\n");
  6891. X        }
  6892. X#ifdef SCAN
  6893. X        do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6894. X#endif /* SCAN */
  6895. X        dd_arch((unsigned char *)header);
  6896. X        skip_file(ds_skip + in_rs);
  6897. X        continue;
  6898. X    }
  6899. X    if(!strncmp(header + I_TYPEOFF, "APPL", 4) &&
  6900. X       !strncmp(header + I_AUTHOFF, "DSEA", 4)) {
  6901. X        if(verbose) {
  6902. X        do_indent(indent);
  6903. X        }
  6904. X        c = getc(infp);
  6905. X        (void)ungetc(c, infp);
  6906. X        if(c == 'D') {
  6907. X        if(verbose) {
  6908. X            (void)fprintf(stderr,
  6909. X            "This is a \"DiskDoubler\" self extracting archive.\n");
  6910. X#ifdef SCAN
  6911. X            do_idf(header + I_NAMEOFF + 1, ARCH_NAME);
  6912. X#endif /* SCAN */
  6913. X        }
  6914. X        dd_arch((unsigned char *)header);
  6915. X        } else {
  6916. X        if(verbose) {
  6917. X            (void)fprintf(stderr,
  6918. X            "This is a \"DiskDoubler\" self decompressing file.\n");
  6919. X#ifdef SCAN
  6920. X            do_idf(header + I_NAMEOFF + 1, PACK_NAME);
  6921. X#endif /* SCAN */
  6922. X        }
  6923. X        dd_file((unsigned char *)header);
  6924. X        }
  6925. X        skip_file(ds_skip + in_rs);
  6926. X        continue;
  6927. X    }
  6928. X#endif /* DD */
  6929. X    if(header[0] == 0 /* MORE CHECKS HERE! */) {
  6930. X        mcb(header, (unsigned long)in_rsrc_size,
  6931. X            (unsigned long)in_data_size, in_ds + in_rs);
  6932. X        continue;
  6933. X    } else {
  6934. X        (void)fprintf(stderr, "Unrecognized archive type.\n");
  6935. X        exit(1);
  6936. X    }
  6937. X    }
  6938. X}
  6939. X
  6940. Xstatic void skip_file(skip)
  6941. Xint skip;
  6942. X{
  6943. X    char buff[1024];
  6944. X    int n;
  6945. X
  6946. X    while(skip > 0) {
  6947. X    n = (skip < 1024 ? skip : 1024);
  6948. X    if(fread(buff, 1, n, infp) != n) {
  6949. X        (void)fprintf(stderr, "Incomplete file.\n");
  6950. X#ifdef SCAN
  6951. X        do_error("macunpack: Incomplete file");
  6952. X#endif /* SCAN */
  6953. X        exit(1);
  6954. X    }
  6955. X    skip -= n;
  6956. X    }
  6957. X}
  6958. X
  6959. X#ifdef SCAN
  6960. Xstatic void get_idf(kind)
  6961. Xint kind;
  6962. X{
  6963. X    char filename[255];
  6964. X
  6965. X    if(fread(filename, 1, in_data_size, infp) != in_data_size) {
  6966. X    (void)fprintf(stderr, "Incomplete file.\n");
  6967. X#ifdef SCAN
  6968. X        do_error("macunpack: Incomplete file");
  6969. X#endif /* SCAN */
  6970. X    exit(1);
  6971. X    }
  6972. X    filename[in_data_size] = 0;
  6973. X    do_idf(filename, kind);
  6974. X}
  6975. X#endif /* SCAN */
  6976. X
  6977. SHAR_EOF
  6978. if test 13547 -ne "`wc -c < 'macbinary.c'`"
  6979. then
  6980.     echo shar: "error transmitting 'macbinary.c'" '(should have been 13547 characters)'
  6981. fi
  6982. fi
  6983. echo shar: "extracting 'globals.c'" '(422 characters)'
  6984. if test -f 'globals.c'
  6985. then
  6986.     echo shar: "will not over-write existing file 'globals.c'"
  6987. else
  6988. sed 's/^X//' << \SHAR_EOF > 'globals.c'
  6989. X#include "globals.h"
  6990. X#include "../fileio/machdr.h"
  6991. X#include "../fileio/wrfile.h"
  6992. X#include "../fileio/kind.h"
  6993. X
  6994. Xchar info[INFOBYTES];
  6995. Xchar text[F_NAMELEN+1];
  6996. X
  6997. Xint list, verbose, info_only, query, write_it, indent, dir_skip, no_dd;
  6998. XFILE *infp;
  6999. Xint in_data_size = -1;
  7000. Xint in_rsrc_size = -1;
  7001. Xint in_ds, in_rs, ds_skip, rs_skip;
  7002. X
  7003. X#ifdef SCAN
  7004. Xvoid do_error(string)
  7005. Xchar *string;
  7006. X{
  7007. X    do_idf(string, ERROR);
  7008. X}
  7009. X#endif /* SCAN */
  7010. X
  7011. SHAR_EOF
  7012. if test 422 -ne "`wc -c < 'globals.c'`"
  7013. then
  7014.     echo shar: "error transmitting 'globals.c'" '(should have been 422 characters)'
  7015. fi
  7016. fi
  7017. echo shar: "extracting 'crc.c'" '(52 characters)'
  7018. if test -f 'crc.c'
  7019. then
  7020.     echo shar: "will not over-write existing file 'crc.c'"
  7021. else
  7022. sed 's/^X//' << \SHAR_EOF > 'crc.c'
  7023. Xunsigned long crcinit;
  7024. X
  7025. Xunsigned long (*updcrc)();
  7026. X
  7027. SHAR_EOF
  7028. if test 52 -ne "`wc -c < 'crc.c'`"
  7029. then
  7030.     echo shar: "error transmitting 'crc.c'" '(should have been 52 characters)'
  7031. fi
  7032. fi
  7033. echo shar: "extracting 'dir.c'" '(1357 characters)'
  7034. if test -f 'dir.c'
  7035. then
  7036.     echo shar: "will not over-write existing file 'dir.c'"
  7037. else
  7038. sed 's/^X//' << \SHAR_EOF > 'dir.c'
  7039. X#include "globals.h"
  7040. X#include "../fileio/machdr.h"
  7041. X#include "../fileio/wrfile.h"
  7042. X#include "../util/util.h"
  7043. X#include "../util/masks.h"
  7044. X
  7045. Xextern char *malloc();
  7046. Xextern char *realloc();
  7047. X
  7048. Xstatic char *dir_stack;
  7049. Xstatic int dir_ptr = -64;
  7050. Xstatic int dir_max;
  7051. X
  7052. Xvoid dir(hdr)
  7053. Xchar *hdr;
  7054. X{
  7055. Xint doit;
  7056. X
  7057. X    if((hdr[I_NAMEOFF] & BYTEMASK) == 0x80) {
  7058. X    if(dir_skip) {
  7059. X        dir_skip--;
  7060. X        return;
  7061. X    }
  7062. X    indent--;
  7063. X    if(list) {
  7064. X        do_indent(indent);
  7065. X        (void)fprintf(stderr, "leaving folder \"%s\"\n",
  7066. X            dir_stack + dir_ptr);
  7067. X    }
  7068. X    if(!info_only) {
  7069. X        enddir();
  7070. X    }
  7071. X    dir_ptr -= 64;
  7072. X    return;
  7073. X    }
  7074. X    if(dir_skip) {
  7075. X    dir_skip++;
  7076. X    return;
  7077. X    }
  7078. X    dir_ptr += 64;
  7079. X    if(dir_ptr == dir_max) {
  7080. X    if(dir_max == 0) {
  7081. X        dir_stack = malloc(64);
  7082. X    } else {
  7083. X        dir_stack = realloc(dir_stack, (unsigned)dir_max + 64);
  7084. X    }
  7085. X    dir_max += 64;
  7086. X    if(dir_stack == NULL) {
  7087. X        (void)fprintf(stderr, "Insufficient memory\n");
  7088. X        exit(1);
  7089. X    }
  7090. X    }
  7091. X    transname(hdr + I_NAMEOFF + 1, dir_stack + dir_ptr,
  7092. X          (int)(hdr[I_NAMEOFF] & 0x7f));
  7093. X    doit = 1;
  7094. X    if(list) {
  7095. X    do_indent(indent);
  7096. X    (void)fprintf(stderr, "folder=\"%s\"", dir_stack + dir_ptr);
  7097. X    if(query) {
  7098. X        doit = do_query();
  7099. X    } else {
  7100. X        (void)fputc('\n', stderr);
  7101. X    }
  7102. X    }
  7103. X    if(!doit) {
  7104. X    dir_ptr -= 64;
  7105. X    dir_skip = 1;
  7106. X    return;
  7107. X    }
  7108. X    if(!info_only) {
  7109. X    do_mkdir(dir_stack + dir_ptr, hdr);
  7110. X    }
  7111. X    indent++;
  7112. X}
  7113. X
  7114. SHAR_EOF
  7115. if test 1357 -ne "`wc -c < 'dir.c'`"
  7116. then
  7117.     echo shar: "error transmitting 'dir.c'" '(should have been 1357 characters)'
  7118. fi
  7119. fi
  7120. echo shar: "extracting 'bin.c'" '(1784 characters)'
  7121. if test -f 'bin.c'
  7122. then
  7123.     echo shar: "will not over-write existing file 'bin.c'"
  7124. else
  7125. sed 's/^X//' << \SHAR_EOF > 'bin.c'
  7126. X#include "macunpack.h"
  7127. X#ifdef BIN
  7128. X#include "globals.h"
  7129. X#include "../fileio/machdr.h"
  7130. X#include "../fileio/wrfile.h"
  7131. X#include "../fileio/kind.h"
  7132. X#include "../util/util.h"
  7133. X#include "../util/masks.h"
  7134. X
  7135. Xextern void mcb();
  7136. X
  7137. Xvoid bin(header, data_size, UMcp)
  7138. Xchar *header;
  7139. Xint data_size, UMcp;
  7140. X{
  7141. X    char hdr[INFOBYTES];
  7142. X    unsigned long rsrcLength, dataLength;
  7143. X
  7144. X    hdr[0] = getb(infp);
  7145. X    (void)ungetc(hdr[0], infp);
  7146. X    if(hdr[0] != 0) {
  7147. X    if(!strncmp(header + I_AUTHOFF, "BnHq", 4) && hdr[0] == '(') {
  7148. X        do_indent(indent);
  7149. X        (void)fprintf(stderr, "Sorry, this is a fake BinHex 5.0 file.  ");
  7150. X        (void)fprintf(stderr, "Debinhex with hexbin first.\n");
  7151. X#ifdef SCAN
  7152. X        do_error("macunpack: fake BinHex 5.0");
  7153. X#endif /* SCAN */
  7154. X    } else {
  7155. X        do_indent(indent);
  7156. X        (void)fprintf(stderr, "Sorry, contents not recognized.\n");
  7157. X#ifdef SCAN
  7158. X        do_error("macunpack: contents not recognized");
  7159. X#endif /* SCAN */
  7160. X    }
  7161. X    do_indent(indent);
  7162. X    (void)fprintf(stderr, "Copying as a plain file.\n");
  7163. X#ifdef SCAN
  7164. X    do_idf("", COPY);
  7165. X#endif /* SCAN */
  7166. X    mcb(header, (unsigned long)in_data_size, (unsigned long)in_rsrc_size,
  7167. X        in_ds + in_rs);
  7168. X    ds_skip = 0;
  7169. X    rs_skip = 0;
  7170. X    in_ds = 0;
  7171. X    in_rs = 0;
  7172. X    return;
  7173. X    }
  7174. X    if(fread(hdr, 1, INFOBYTES - 1, infp) != INFOBYTES) {
  7175. X    (void)fprintf(stderr, "Can't read file header\n");
  7176. X#ifdef SCAN
  7177. X    do_error("macunpack: Can't read file header");
  7178. X#endif /* SCAN */
  7179. X    exit(1);
  7180. X    }
  7181. X    rsrcLength = get4(hdr + I_RLENOFF);
  7182. X    dataLength = get4(hdr + I_DLENOFF);
  7183. X    if(UMcp) {
  7184. X    /* Why this?  Moreover, we are losing the bundle bit! */
  7185. X    put4(hdr + I_RLENOFF, ++rsrcLength);
  7186. X    put4(hdr + I_DLENOFF, ++dataLength);
  7187. X    }
  7188. X    mcb(hdr, rsrcLength, dataLength, data_size - INFOBYTES);
  7189. X}
  7190. X#else /* BIN */
  7191. Xint bin; /* keep lint and some compilers happy */
  7192. X#endif /* BIN */
  7193. X
  7194. SHAR_EOF
  7195. if test 1784 -ne "`wc -c < 'bin.c'`"
  7196. then
  7197.     echo shar: "error transmitting 'bin.c'" '(should have been 1784 characters)'
  7198. fi
  7199. fi
  7200. echo shar: "extracting 'crc.h'" '(306 characters)'
  7201. if test -f 'crc.h'
  7202. then
  7203.     echo shar: "will not over-write existing file 'crc.h'"
  7204. else
  7205. sed 's/^X//' << \SHAR_EOF > 'crc.h'
  7206. X#define INIT_CRC crcinit
  7207. X
  7208. Xextern unsigned long arc_crcinit;
  7209. Xextern unsigned long binhex_crcinit;
  7210. Xextern unsigned long zip_crcinit;
  7211. X
  7212. Xextern unsigned long arc_updcrc();
  7213. Xextern unsigned long binhex_updcrc();
  7214. Xextern unsigned long zip_updcrc();
  7215. X
  7216. Xextern unsigned long crcinit;
  7217. Xextern unsigned long (*updcrc)();
  7218. X
  7219. SHAR_EOF
  7220. if test 306 -ne "`wc -c < 'crc.h'`"
  7221. then
  7222.     echo shar: "error transmitting 'crc.h'" '(should have been 306 characters)'
  7223. fi
  7224. fi
  7225. echo shar: "extracting 'globals.h'" '(302 characters)'
  7226. if test -f 'globals.h'
  7227. then
  7228.     echo shar: "will not over-write existing file 'globals.h'"
  7229. else
  7230. sed 's/^X//' << \SHAR_EOF > 'globals.h'
  7231. X#include <stdio.h>
  7232. X
  7233. Xextern void exit();
  7234. Xextern void transname();
  7235. Xextern void do_error();
  7236. X
  7237. Xextern char info[];
  7238. Xextern char text[];
  7239. X
  7240. Xextern int list, verbose, info_only, query, write_it, indent, dir_skip, no_dd;
  7241. Xextern FILE *infp;
  7242. X
  7243. Xextern int in_data_size, in_rsrc_size, in_ds, in_rs, ds_skip, rs_skip;
  7244. X
  7245. SHAR_EOF
  7246. if test 302 -ne "`wc -c < 'globals.h'`"
  7247. then
  7248.     echo shar: "error transmitting 'globals.h'" '(should have been 302 characters)'
  7249. fi
  7250. fi
  7251. echo shar: "extracting 'pit.h'" '(870 characters)'
  7252. if test -f 'pit.h'
  7253. then
  7254.     echo shar: "will not over-write existing file 'pit.h'"
  7255. else
  7256. sed 's/^X//' << \SHAR_EOF > 'pit.h'
  7257. X#define H_NAMELEN 63
  7258. X
  7259. X#define H_NLENOFF 0
  7260. X#define H_NAMEOFF 1
  7261. X#define H_TYPEOFF 64
  7262. X#define H_AUTHOFF 68
  7263. X#define H_FLAGOFF 72
  7264. X#define    H_LOCKOFF 74
  7265. X#define H_DLENOFF 76
  7266. X#define H_RLENOFF 80
  7267. X#define H_CTIMOFF 84
  7268. X#define H_MTIMOFF 88
  7269. X#define H_HDRCRC  92
  7270. X#define HDRBYTES  94
  7271. X
  7272. Xstruct pit_header {        /* Packit file header (92 bytes) */
  7273. X    unsigned char nlen;    /* number of characters in packed file name */
  7274. X    char name[63];        /* name of packed file */
  7275. X    char type[4];        /* file type */
  7276. X    char auth[4];        /* file creator */
  7277. X    unsigned short flags;    /* file flags (?) */
  7278. X    unsigned short lock;    /* unknown */
  7279. X    unsigned long dlen;    /* number of bytes in data fork */
  7280. X    unsigned long rlen;    /* number of bytes in resource fork */
  7281. X    unsigned long ctim;    /* file creation time */
  7282. X    unsigned long mtim;    /* file modified time */
  7283. X    unsigned short hdrCRC;    /* CRC */
  7284. X};
  7285. X
  7286. X#define nocomp    0
  7287. X#define huffman    1
  7288. X
  7289. SHAR_EOF
  7290. if test 870 -ne "`wc -c < 'pit.h'`"
  7291. then
  7292.     echo shar: "error transmitting 'pit.h'" '(should have been 870 characters)'
  7293. fi
  7294. fi
  7295. echo shar: "extracting 'sit.h'" '(2682 characters)'
  7296. if test -f 'sit.h'
  7297. then
  7298.     echo shar: "will not over-write existing file 'sit.h'"
  7299. else
  7300. sed 's/^X//' << \SHAR_EOF > 'sit.h'
  7301. X#define S_SIGNATURE    0
  7302. X#define S_NUMFILES     4
  7303. X#define S_ARCLENGTH    6
  7304. X#define S_SIGNATURE2  10
  7305. X#define    S_VERSION     14
  7306. X#define SITHDRSIZE    22
  7307. X
  7308. X#define F_COMPRMETHOD    0
  7309. X#define F_COMPDMETHOD    1
  7310. X#define F_FNAME          2
  7311. X#define F_FTYPE         66
  7312. X#define F_CREATOR       70
  7313. X#define F_FNDRFLAGS     74
  7314. X#define F_CREATIONDATE  76
  7315. X#define F_MODDATE       80
  7316. X#define F_RSRCLENGTH    84
  7317. X#define F_DATALENGTH    88
  7318. X#define F_COMPRLENGTH   92
  7319. X#define F_COMPDLENGTH   96
  7320. X#define F_RSRCCRC      100
  7321. X#define F_DATACRC      102
  7322. X#define F_HDRCRC       110
  7323. X#define FILEHDRSIZE    112
  7324. X
  7325. Xtypedef long OSType;
  7326. X
  7327. Xtypedef struct sitHdr {            /* 22 bytes */
  7328. X    OSType    signature;        /* = 'SIT!' -- for verification */
  7329. X    unsigned short    numFiles;    /* number of files in archive */
  7330. X    unsigned long    arcLength;    /* length of entire archive incl.
  7331. X                        hdr. -- for verification */
  7332. X    OSType    signature2;        /* = 'rLau' -- for verification */
  7333. X    unsigned char    version;    /* version number */
  7334. X    char reserved[7];
  7335. X};
  7336. X
  7337. Xtypedef struct fileHdr {        /* 112 bytes */
  7338. X    unsigned char    compRMethod;    /* rsrc fork compression method */
  7339. X    unsigned char    compDMethod;    /* data fork compression method */
  7340. X    unsigned char    fName[64];    /* a STR63 */
  7341. X    OSType    fType;            /* file type */
  7342. X    OSType    fCreator;        /* er... */
  7343. X    unsigned short FndrFlags;    /* copy of Finder flags.  For our
  7344. X                        purposes, we can clear:
  7345. X                        busy,onDesk */
  7346. X    unsigned long    creationDate;
  7347. X    unsigned long    modDate;    /* !restored-compat w/backup prgms */
  7348. X    unsigned long    rsrcLength;    /* decompressed lengths */
  7349. X    unsigned long    dataLength;
  7350. X    unsigned long    compRLength;    /* compressed lengths */
  7351. X    unsigned long    compDLength;
  7352. X    unsigned short rsrcCRC;        /* crc of rsrc fork */
  7353. X    unsigned short dataCRC;        /* crc of data fork */
  7354. X    char reserved[6];
  7355. X    unsigned short hdrCRC;        /* crc of file header */
  7356. X};
  7357. X
  7358. X
  7359. X/* file format is:
  7360. X    sitArchiveHdr
  7361. X        file1Hdr
  7362. X            file1RsrcFork
  7363. X            file1DataFork
  7364. X        file2Hdr
  7365. X            file2RsrcFork
  7366. X            file2DataFork
  7367. X        .
  7368. X        .
  7369. X        .
  7370. X        fileNHdr
  7371. X            fileNRsrcFork
  7372. X            fileNDataFork
  7373. X*/
  7374. X
  7375. X
  7376. X
  7377. X/* compression methods */
  7378. X#define nocomp    0    /* just read each byte and write it to archive */
  7379. X#define rle    1    /* RLE compression */
  7380. X#define lzc    2    /* LZC compression */
  7381. X#define huffman    3    /* Huffman compression */
  7382. X#define lzah    5    /* LZ with adaptive Huffman */
  7383. X#define fixhuf    6    /* Fixed Huffman table */
  7384. X#define mw    8    /* Miller-Wegman encoding */
  7385. X/* this bit says whether the file is protected or not */
  7386. X#define prot    16    /* password protected bit */
  7387. X/* rsrc & data compress are identical here: */
  7388. X#define sfolder    32    /* start of folder */
  7389. X#define efolder    33    /* end of folder */
  7390. X#define sknown    0x16f    /* known compression methods */
  7391. X
  7392. X/* all other numbers are reserved */
  7393. X
  7394. X#define    ESC    0x90    /* repeat packing escape */
  7395. X
  7396. SHAR_EOF
  7397. if test 2682 -ne "`wc -c < 'sit.h'`"
  7398. then
  7399.     echo shar: "error transmitting 'sit.h'" '(should have been 2682 characters)'
  7400. fi
  7401. fi
  7402. echo shar: "extracting 'huffman.h'" '(222 characters)'
  7403. if test -f 'huffman.h'
  7404. then
  7405.     echo shar: "will not over-write existing file 'huffman.h'"
  7406. else
  7407. sed 's/^X//' << \SHAR_EOF > 'huffman.h'
  7408. X#define    HUFF_BE        0
  7409. X#define    HUFF_LE        1
  7410. X
  7411. Xtypedef struct node {
  7412. X    int flag, byte;
  7413. X    struct node *one, *zero;
  7414. X} node;
  7415. X
  7416. Xextern int (*get_bit)();
  7417. Xextern void clrhuff();
  7418. X
  7419. Xextern struct node nodelist[];
  7420. Xextern int bytesread;
  7421. X
  7422. SHAR_EOF
  7423. if test 222 -ne "`wc -c < 'huffman.h'`"
  7424. then
  7425.     echo shar: "error transmitting 'huffman.h'" '(should have been 222 characters)'
  7426. fi
  7427. fi
  7428. echo shar: "extracting 'cpt.h'" '(2461 characters)'
  7429. if test -f 'cpt.h'
  7430. then
  7431.     echo shar: "will not over-write existing file 'cpt.h'"
  7432. else
  7433. sed 's/^X//' << \SHAR_EOF > 'cpt.h'
  7434. X#define C_SIGNATURE    0
  7435. X#define C_VOLUME       1
  7436. X#define C_XMAGIC       2
  7437. X#define C_IOFFSET      4
  7438. X#define CPTHDRSIZE     8
  7439. X
  7440. X#define C_HDRCRC       0
  7441. X#define C_ENTRIES      4
  7442. X#define C_COMMENT      6
  7443. X#define CPTHDR2SIZE    7
  7444. X
  7445. X#define CHDRSIZE       (CPTHDRSIZE+CPTHDR2SIZE)
  7446. X
  7447. X#define F_FNAME          0
  7448. X#define F_FOLDER        32
  7449. X#define F_FOLDERSIZE    33
  7450. X#define F_VOLUME        35
  7451. X#define F_FILEPOS       36
  7452. X#define F_FTYPE         40
  7453. X#define F_CREATOR       44
  7454. X#define F_CREATIONDATE  48
  7455. X#define F_MODDATE       52
  7456. X#define F_FNDRFLAGS     56
  7457. X#define F_FILECRC       58
  7458. X#define F_CPTFLAG       62
  7459. X#define F_RSRCLENGTH    64
  7460. X#define F_DATALENGTH    68
  7461. X#define F_COMPRLENGTH   72
  7462. X#define F_COMPDLENGTH   76
  7463. X#define FILEHDRSIZE     80
  7464. X
  7465. Xtypedef long    OSType;
  7466. X
  7467. Xtypedef struct cptHdr {            /* 8 bytes */
  7468. X    unsigned char    signature;    /* = 1 -- for verification */
  7469. X    unsigned char    volume;        /* for multi-file archives */
  7470. X    unsigned short    xmagic;        /* verification multi-file consistency*/
  7471. X    unsigned long    offset;        /* index offset */
  7472. X/* The following are really in header2 at offset */
  7473. X    unsigned long    hdrcrc;        /* header crc */
  7474. X    unsigned short    entries;    /* number of index entries */
  7475. X    unsigned char    commentsize;    /* number of bytes comment that follow*/
  7476. X};
  7477. X
  7478. Xtypedef struct fileHdr {        /* 78 bytes */
  7479. X    unsigned char    fName[32];    /* a STR32 */
  7480. X    unsigned char    folder;        /* set to 1 if a folder */
  7481. X    unsigned short    foldersize;    /* number of entries in folder */
  7482. X    unsigned char    volume;        /* for multi-file archives */
  7483. X    unsigned long    filepos;    /* position of data in file */
  7484. X    OSType    fType;            /* file type */
  7485. X    OSType    fCreator;        /* er... */
  7486. X    unsigned long    creationDate;
  7487. X    unsigned long    modDate;    /* !restored-compat w/backup prgms */
  7488. X    unsigned short FndrFlags;    /* copy of Finder flags.  For our
  7489. X                        purposes, we can clear:
  7490. X                        busy,onDesk */
  7491. X    unsigned long    fileCRC;    /* crc on file */
  7492. X    unsigned short    cptFlag;    /* cpt flags */
  7493. X    unsigned long    rsrcLength;    /* decompressed lengths */
  7494. X    unsigned long    dataLength;
  7495. X    unsigned long    compRLength;    /* compressed lengths */
  7496. X    unsigned long    compDLength;
  7497. X};
  7498. X
  7499. X
  7500. X/* file format is:
  7501. X    cptArchiveHdr
  7502. X        file1data
  7503. X            file1RsrcFork
  7504. X            file1DataFork
  7505. X        file2data
  7506. X            file2RsrcFork
  7507. X            file2DataFork
  7508. X        .
  7509. X        .
  7510. X        .
  7511. X        fileNdata
  7512. X            fileNRsrcFork
  7513. X            fileNDataFork
  7514. X    cptIndex
  7515. X*/
  7516. X
  7517. X
  7518. X
  7519. X/* cpt flags */
  7520. X#define encryp    1    /* file is encrypted */
  7521. X#define crsrc    2    /* resource fork is compressed */
  7522. X#define cdata    4    /* data fork is compressed */
  7523. X/*      ????    8    /* unknown */
  7524. X
  7525. X#define CIRCSIZE    8192
  7526. X
  7527. SHAR_EOF
  7528. if test 2461 -ne "`wc -c < 'cpt.h'`"
  7529. then
  7530.     echo shar: "error transmitting 'cpt.h'" '(should have been 2461 characters)'
  7531. fi
  7532. fi
  7533. echo shar: "extracting 'stf.c'" '(4993 characters)'
  7534. if test -f 'stf.c'
  7535. then
  7536.     echo shar: "will not over-write existing file 'stf.c'"
  7537. else
  7538. sed 's/^X//' << \SHAR_EOF > 'stf.c'
  7539. X#include "macunpack.h"
  7540. X#ifdef STF
  7541. X#include "stf.h"
  7542. X#include "globals.h"
  7543. X#include "huffman.h"
  7544. X#include "../util/curtime.h"
  7545. X#include "../fileio/wrfile.h"
  7546. X#include "../fileio/machdr.h"
  7547. X#include "../util/util.h"
  7548. X
  7549. Xextern void de_huffman();
  7550. Xextern void set_huffman();
  7551. X
  7552. Xtypedef struct{
  7553. X    int num;
  7554. X    int next;
  7555. X} table_struct;
  7556. X
  7557. Xstatic table_struct table[511];
  7558. Xstatic char length[256];
  7559. X
  7560. Xstatic void stf_wrfile();
  7561. Xstatic void stf_wrfork();
  7562. Xstatic void stf_construct();
  7563. X
  7564. Xvoid stf(ibytes)
  7565. Xunsigned long ibytes;
  7566. X{
  7567. X    char magic[3], fauth[5], ftype[5];
  7568. X    int filel, i;
  7569. X    unsigned int rsrcLength, dataLength;
  7570. X    unsigned long curtime;
  7571. X
  7572. X    set_huffman(HUFF_LE);
  7573. X    for(i = 0; i < 3; i++) {
  7574. X    magic[i] = getb(infp);
  7575. X    }
  7576. X    if(strncmp(magic, MAGIC, 3)) {
  7577. X    (void)fprintf(stderr, "Error in magic header.\n");
  7578. X#ifdef SCAN
  7579. X    do_error("macunpack: Error in magic header");
  7580. X#endif /* SCAN */
  7581. X    exit(1);
  7582. X    }
  7583. X    for(i = 0; i < INFOBYTES; i++) {
  7584. X    info[i] = 0;
  7585. X    }
  7586. X    filel = getb(infp);
  7587. X    info[I_NAMEOFF] = filel;
  7588. X    i = filel;
  7589. X    for(i = 1; i <= filel; i++) {
  7590. X    info[I_NAMEOFF + i] = getb(infp);
  7591. X    }
  7592. X    for(i = 0; i < 4; i++) {
  7593. X    info[I_TYPEOFF + i] = getb(infp);
  7594. X    }
  7595. X    for(i = 0; i < 4; i++) {
  7596. X    info[I_AUTHOFF + i] = getb(infp);
  7597. X    }
  7598. X    curtime = (unsigned long)time((time_t *)0) + TIMEDIFF;
  7599. X    put4(info + I_CTIMOFF, curtime);
  7600. X    put4(info + I_MTIMOFF, curtime);
  7601. X    rsrcLength = 0;
  7602. X    for(i = 0; i < 4; i++) {
  7603. X    rsrcLength = (rsrcLength << 8) + getb(infp);
  7604. X    }
  7605. X    put4(info + I_RLENOFF, (unsigned long)rsrcLength);
  7606. X    dataLength = 0;
  7607. X    for(i = 0; i < 4; i++) {
  7608. X    dataLength = (dataLength << 8) + getb(infp);
  7609. X    }
  7610. X    put4(info + I_DLENOFF, (unsigned long)dataLength);
  7611. X    ibytes -= filel + 20;
  7612. X    write_it = 1;
  7613. X    if(list) {
  7614. X    transname(info + I_NAMEOFF + 1, text, (int)info[I_NAMEOFF]);
  7615. X    transname(info + I_TYPEOFF, ftype, 4);
  7616. X    transname(info + I_AUTHOFF, fauth, 4);
  7617. X    do_indent(indent);
  7618. X    (void)fprintf(stderr,
  7619. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  7620. X        text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  7621. X    if(info_only) {
  7622. X        write_it = 0;
  7623. X    }
  7624. X    if(query) {
  7625. X        write_it = do_query();
  7626. X    } else {
  7627. X        (void)fputc('\n', stderr);
  7628. X    }
  7629. X    }
  7630. X    stf_wrfile((unsigned long)rsrcLength, (unsigned long)dataLength, ibytes);
  7631. X}
  7632. X
  7633. Xstatic void stf_wrfile(rsrcLength, dataLength, ibytes)
  7634. Xunsigned long rsrcLength, dataLength, ibytes;
  7635. X{
  7636. X    unsigned long num = 0;
  7637. X
  7638. X    if(write_it) {
  7639. X    define_name(text);
  7640. X    start_info(info, rsrcLength, dataLength);
  7641. X    start_rsrc();
  7642. X    stf_wrfork(&num, rsrcLength, 0);
  7643. X    start_data();
  7644. X    stf_wrfork(&num, rsrcLength + dataLength, (int)(rsrcLength & 0xfff));
  7645. X    end_file();
  7646. X    } else {
  7647. X    for(num = 0; num < ibytes; num++) {
  7648. X        (void)getb(infp);
  7649. X    }
  7650. X    }
  7651. X    if(verbose) {
  7652. X    (void)fprintf(stderr, "\tHuffman compressed (%4.1f%%).\n",
  7653. X        100.0 * ibytes / (rsrcLength + dataLength));
  7654. X    }
  7655. X}
  7656. X
  7657. Xstatic void stf_wrfork(num, towrite, offs)
  7658. Xunsigned long *num, towrite;
  7659. Xint offs;
  7660. X{
  7661. X    int c, k, max, i, i1;
  7662. X    char *tmp_out_ptr;
  7663. X
  7664. X    while(*num < towrite) {
  7665. X    if((*num & 0xfff) == 0) {
  7666. X        clrhuff();
  7667. X        c = getb(infp) & 0xff;
  7668. X        k = c;
  7669. X        max = 0;
  7670. X        for(i = 0; i < k; i++) {
  7671. X        c = getb(infp) & 0xff;
  7672. X        nodelist[i + 1].flag = 1;
  7673. X        nodelist[i + 1].byte = i + 1;
  7674. X        table[i + 1].num = c;
  7675. X        table[i + 1].next = 0;
  7676. X        if(c > max) {
  7677. X            max = c;
  7678. X        }
  7679. X        }
  7680. X        for(i = k; i < 32; i++) {
  7681. X        nodelist[i + 1].flag = 1;
  7682. X        nodelist[i + 1].byte = i + 1;
  7683. X        table[i + 1].num = 0;
  7684. X        table[i + 1].next = 0;
  7685. X        }
  7686. X        k = 0;
  7687. X        for(i = 0; i <= max; i++) {
  7688. X        for(i1 = 1; i1 < 33; i1++) {
  7689. X            if(table[i1].num == i) {
  7690. X            table[k].next = i1;
  7691. X            k = i1;
  7692. X            }
  7693. X        }
  7694. X        }
  7695. X        stf_construct(32);
  7696. X        tmp_out_ptr = out_ptr;
  7697. X        out_ptr = length;
  7698. X        de_huffman((unsigned long)256);
  7699. X        out_ptr = tmp_out_ptr;
  7700. X        for(i = 1; i < 257; i++) {
  7701. X        table[i].num = 0x40000000 >> length[i - 1];
  7702. X        nodelist[i].flag = 1;
  7703. X        nodelist[i].byte = i - 1;
  7704. X        table[i].next = 0;
  7705. X        }
  7706. X        k = 0;
  7707. X        for(i = 1; i < 0x40000000; i <<= 1) {
  7708. X        for(i1 = 1; i1 < 257; i1++) {
  7709. X            if(table[i1].num == i) {
  7710. X            table[k].next = i1;
  7711. X            k = i1;
  7712. X            }
  7713. X        }
  7714. X        }
  7715. X        stf_construct(256);
  7716. X    }
  7717. X    i = 0x1000 - offs;
  7718. X    offs = 0;
  7719. X    if(i > towrite - *num) {
  7720. X        i = towrite - *num;
  7721. X    }
  7722. X    de_huffman((unsigned long)i);
  7723. X    *num += i;
  7724. X    }
  7725. X}
  7726. X
  7727. Xstatic void stf_construct(n)
  7728. Xint n;
  7729. X{
  7730. X    int i, i1, i2, j1, k;
  7731. X
  7732. X    j1 = n + 1;
  7733. X    i = table[0].next;
  7734. X    i1 = table[i].next;
  7735. X    while(table[i1].next != 0) {
  7736. X    k = table[i].num + table[i1].num;
  7737. X    table[j1].num = k;
  7738. X    nodelist[j1].flag = 0;
  7739. X    nodelist[j1].zero = nodelist + i;
  7740. X    nodelist[j1].one = nodelist + i1;
  7741. X    i2 = i1;
  7742. X    i = table[i2].next;
  7743. X    while(i != 0 && table[i].num <= k) {
  7744. X        i2 = i;
  7745. X        i = table[i].next;
  7746. X    }
  7747. X    table[j1].next = i;
  7748. X    table[i2].next = j1;
  7749. X    i = table[i1].next;
  7750. X    i1 = table[i].next;
  7751. X    j1++;
  7752. X    }
  7753. X    table[0].num = table[i].num + table[i1].num;
  7754. X    nodelist[0].flag = 0;
  7755. X    nodelist[0].zero = nodelist + i;
  7756. X    nodelist[0].one = nodelist + i1;
  7757. X}
  7758. X#else /* STF */
  7759. Xint stf; /* keep lint and some compilers happy */
  7760. X#endif /* STF */
  7761. X
  7762. SHAR_EOF
  7763. if test 4993 -ne "`wc -c < 'stf.c'`"
  7764. then
  7765.     echo shar: "error transmitting 'stf.c'" '(should have been 4993 characters)'
  7766. fi
  7767. fi
  7768. echo shar: "extracting 'zma.h'" '(2074 characters)'
  7769. if test -f 'zma.h'
  7770. then
  7771.     echo shar: "will not over-write existing file 'zma.h'"
  7772. else
  7773. sed 's/^X//' << \SHAR_EOF > 'zma.h'
  7774. X#include "zmahdr.h"
  7775. X
  7776. X#define    Z_HDRSIZE    78
  7777. X
  7778. X#define    Z_WHAT        0    /* What kind of data? */
  7779. X#define    Z_HLEN        1    /* Header length */
  7780. X#define    Z_BFLAGS    2    /* Boolean flags */
  7781. X#define    Z_NEXT        4    /* Pointer to next entry */
  7782. X#define    Z_CRLEN        8    /* Length compressed resource */
  7783. X#define    Z_CDLEN        12    /* Length compressed data */
  7784. X#define    Z_URLEN        16    /* Length uncompressed resource */
  7785. X#define    Z_UDLEN        20    /* Length uncompressed data */
  7786. X#define    Z_TYPE        24    /* File type */
  7787. X#define    Z_AUTH        28    /* File creator */
  7788. X#define Z_CONTS        28    /* Directory contents pointer; overlayed */
  7789. X#define    Z_MDATE        32    /* Date */
  7790. X#define    Z_COMMENT    36    /* Comment offset, currently unused */
  7791. X#define    Z_FLAGS        40    /* Finder flags */
  7792. X#define    Z_DCRC        42    /* Data crc */
  7793. X#define    Z_RCRC        44    /* Resource crc */
  7794. X#define    Z_FNAME        46    /* File name length and name */
  7795. X
  7796. Xtypedef struct fileHdr {        /* 78 bytes */
  7797. X    char        deleted;    /* Not in original, split off from: */
  7798. X    char        what;        /* What kind?  Negative if deleted */
  7799. X    unsigned char    hlen ;        /* Header length */
  7800. X    unsigned short    boolFlags;    /* Boolean flags */
  7801. X    unsigned long    next;        /* Next entry */
  7802. X    unsigned long    compRLength;    /* The compressed lengths. */
  7803. X    unsigned long    compDLength;    /* For dirs, the second is # entries */
  7804. X    unsigned long    rsrcLength;    /* The uncompressed lengths. */
  7805. X    unsigned long    dataLength;
  7806. X    unsigned long    fType;        /* file type */
  7807. X    unsigned long    fCreator;    /* er... */
  7808. X    unsigned long    modDate;    /* !restored-compat w/backup prgms */
  7809. X    unsigned long    comment;    /* Comment offset */
  7810. X    unsigned short    FndrFlags;    /* copy of Finder flags.  For our
  7811. X                        purposes, we can clear:
  7812. X                        busy,onDesk */
  7813. X    unsigned short    dataCRC;    /* Data fork crc */
  7814. X    unsigned short    rsrcCRC;    /* Resource fork crc */
  7815. X    unsigned char    fName[32];    /* a STR32 */
  7816. X    /* The following are overlayed in the original structure */
  7817. X    unsigned long    conts;        /* Pointer to directory contents */
  7818. X};
  7819. X
  7820. X/* zma types (see what) */
  7821. X#define    z_noth    0    /* ??? */
  7822. X#define z_file    1    /* file is compressed */
  7823. X#define z_plain    2    /* file is uncompressed */
  7824. X#define    z_dir    3    /* directory */
  7825. X#define    z_plug    4    /* for plug in, not supported */
  7826. X
  7827. SHAR_EOF
  7828. if test 2074 -ne "`wc -c < 'zma.h'`"
  7829. then
  7830.     echo shar: "error transmitting 'zma.h'" '(should have been 2074 characters)'
  7831. fi
  7832. fi
  7833. echo shar: "extracting 'stf.h'" '(300 characters)'
  7834. if test -f 'stf.h'
  7835. then
  7836.     echo shar: "will not over-write existing file 'stf.h'"
  7837. else
  7838. sed 's/^X//' << \SHAR_EOF > 'stf.h'
  7839. X#define MAGIC    "RTH"
  7840. X
  7841. X#define    S_MAGIC        0
  7842. X#define    S_FLENGTH    3
  7843. X#define    S_RSRCLNGTH    3    /* + NAMELENGTH */
  7844. X#define    S_DATALNGTH    7    /* + NAMELENGTH */
  7845. X
  7846. Xtypedef struct fileHdr {
  7847. X    char        magic[3];
  7848. X    char        flength;
  7849. X    char        fname[32];    /* actually flength */
  7850. X    unsigned long    rsrcLength;
  7851. X    unsigned long    dataLength;
  7852. X};
  7853. X
  7854. SHAR_EOF
  7855. if test 300 -ne "`wc -c < 'stf.h'`"
  7856. then
  7857.     echo shar: "error transmitting 'stf.h'" '(should have been 300 characters)'
  7858. fi
  7859. fi
  7860. echo shar: "extracting 'bits_be.h'" '(220 characters)'
  7861. if test -f 'bits_be.h'
  7862. then
  7863.     echo shar: "will not over-write existing file 'bits_be.h'"
  7864. else
  7865. sed 's/^X//' << \SHAR_EOF > 'bits_be.h'
  7866. X#define    BITBUFSIZ    16
  7867. X
  7868. Xextern unsigned int bit_be_bitbuf;
  7869. Xextern char *bit_be_filestart;
  7870. Xextern int bit_be_inbytes;
  7871. X
  7872. Xextern void bit_be_fillbuf();
  7873. Xextern unsigned int bit_be_getbits();
  7874. Xextern void bit_be_init_getbits();
  7875. X
  7876. SHAR_EOF
  7877. if test 220 -ne "`wc -c < 'bits_be.h'`"
  7878. then
  7879.     echo shar: "error transmitting 'bits_be.h'" '(should have been 220 characters)'
  7880. fi
  7881. fi
  7882. echo shar: "extracting 'bits_be.c'" '(947 characters)'
  7883. if test -f 'bits_be.c'
  7884. then
  7885.     echo shar: "will not over-write existing file 'bits_be.c'"
  7886. else
  7887. sed 's/^X//' << \SHAR_EOF > 'bits_be.c'
  7888. X#include "../util/masks.h"
  7889. X#include "bits_be.h"
  7890. X
  7891. Xunsigned int bit_be_bitbuf;
  7892. Xchar *bit_be_filestart;
  7893. Xint bit_be_inbytes;
  7894. X
  7895. Xstatic unsigned int bit_be_subbitbuf;
  7896. Xstatic int bit_be_bitcount;
  7897. X
  7898. Xvoid bit_be_fillbuf(n)  /* Shift bit_be_bitbuf n bits left, read n bits */
  7899. Xint n;
  7900. X{
  7901. X    bit_be_bitbuf <<= n;
  7902. X    while (n > bit_be_bitcount) {
  7903. X    bit_be_bitbuf |= bit_be_subbitbuf << (n -= bit_be_bitcount);
  7904. X    if(bit_be_inbytes == 0) {
  7905. X        bit_be_subbitbuf = 0;
  7906. X    } else {
  7907. X        bit_be_subbitbuf = *bit_be_filestart++ & BYTEMASK;
  7908. X        bit_be_inbytes--;
  7909. X    }
  7910. X    bit_be_bitcount = 8;
  7911. X    }
  7912. X    bit_be_bitbuf |= bit_be_subbitbuf >> (bit_be_bitcount -= n);
  7913. X    bit_be_bitbuf &= WORDMASK;
  7914. X}
  7915. X
  7916. Xunsigned int bit_be_getbits(n)
  7917. Xint n;
  7918. X{
  7919. X    unsigned int x;
  7920. X
  7921. X    x = bit_be_bitbuf >> (BITBUFSIZ - n);
  7922. X    bit_be_fillbuf(n);
  7923. X    return x;
  7924. X}
  7925. X
  7926. Xvoid bit_be_init_getbits()
  7927. X{
  7928. X    bit_be_bitbuf = 0;
  7929. X    bit_be_subbitbuf = 0;
  7930. X    bit_be_bitcount = 0;
  7931. X    bit_be_fillbuf(BITBUFSIZ);
  7932. X}
  7933. X
  7934. SHAR_EOF
  7935. if test 947 -ne "`wc -c < 'bits_be.c'`"
  7936. then
  7937.     echo shar: "error transmitting 'bits_be.c'" '(should have been 947 characters)'
  7938. fi
  7939. fi
  7940. echo shar: "extracting 'zmahdr.h'" '(68 characters)'
  7941. if test -f 'zmahdr.h'
  7942. then
  7943.     echo shar: "will not over-write existing file 'zmahdr.h'"
  7944. else
  7945. sed 's/^X//' << \SHAR_EOF > 'zmahdr.h'
  7946. X#define ZMAHDR    "\005\237\032"
  7947. X#define ZMAHDRS    3
  7948. X#define ZMAHDRS2    7
  7949. X
  7950. SHAR_EOF
  7951. if test 68 -ne "`wc -c < 'zmahdr.h'`"
  7952. then
  7953.     echo shar: "error transmitting 'zmahdr.h'" '(should have been 68 characters)'
  7954. fi
  7955. fi
  7956. echo shar: "extracting 'macunpack.c'" '(4173 characters)'
  7957. if test -f 'macunpack.c'
  7958. then
  7959.     echo shar: "will not over-write existing file 'macunpack.c'"
  7960. else
  7961. sed 's/^X//' << \SHAR_EOF > 'macunpack.c'
  7962. X#include "macunpack.h"
  7963. X#include "globals.h"
  7964. X#include "../util/patchlevel.h"
  7965. X#include "../fileio/wrfile.h"
  7966. X#include "../fileio/wrfileopt.h"
  7967. X#include "../fileio/kind.h"
  7968. X#include "../util/util.h"
  7969. X
  7970. X#define LOCALOPT    "ilvqVH"
  7971. X
  7972. Xextern char *strcat();
  7973. X#ifdef STF
  7974. Xextern void stf();
  7975. X#endif /* STF */
  7976. X#ifdef PIT
  7977. Xextern void pit();
  7978. X#endif /* PIT */
  7979. X#ifdef SIT
  7980. Xextern void sit();
  7981. X#endif /* SIT */
  7982. X#ifdef CPT
  7983. Xextern void cpt();
  7984. X#endif /* CPT */
  7985. Xvoid macbinary();
  7986. X
  7987. Xstatic void usage();
  7988. X
  7989. Xstatic char options[128];
  7990. X
  7991. Xint main(argc, argv)
  7992. Xint argc;
  7993. Xchar *argv[];
  7994. X{
  7995. X    int c;
  7996. X    extern int optind;
  7997. X    extern char *optarg;
  7998. X    int errflg;
  7999. X
  8000. X    set_wrfileopt(0);
  8001. X    (void)strcat(options, get_wrfileopt());
  8002. X    (void)strcat(options, LOCALOPT);
  8003. X    errflg = 0;
  8004. X
  8005. X    while((c = getopt(argc, argv, options)) != EOF) {
  8006. X#ifdef SCAN
  8007. X    if(c == 'S') {
  8008. X        no_dd++;
  8009. X    }
  8010. X#endif /* SCAN */
  8011. X    if(!wrfileopt((char)c)) {
  8012. X        switch(c) {
  8013. X        case 'l':
  8014. X        list++;
  8015. X        break;
  8016. X        case 'q':
  8017. X        query++;
  8018. X        break;
  8019. X        case 'v':
  8020. X        verbose++;
  8021. X        break;
  8022. X        case 'i':
  8023. X        info_only++;
  8024. X        break;
  8025. X        case '?':
  8026. X        errflg++;
  8027. X        break;
  8028. X        case 'H':
  8029. X        give_wrfileopt();
  8030. X        (void)fprintf(stderr, "Macunpack specific options:\n");
  8031. X        (void)fprintf(stderr,
  8032. X            "-i:\tgive information only, do not unpack\n");
  8033. X        (void)fprintf(stderr, "-l:\tgive listing\n");
  8034. X        (void)fprintf(stderr, "-v:\tgive verbose listing\n");
  8035. X        (void)fprintf(stderr,
  8036. X            "-q:\tquery for every file/folder before unpacking\n");
  8037. X        (void)fprintf(stderr,
  8038. X            "-V:\tgive information about this version\n");
  8039. X        (void)fprintf(stderr, "-H:\tthis message\n");
  8040. X        (void)fprintf(stderr, "Default is silent unpacking\n");
  8041. X        exit(0);
  8042. X        case 'V':
  8043. X        (void)fprintf(stderr, "Version %s, ", VERSION);
  8044. X        (void)fprintf(stderr, "patchlevel %d", PATCHLEVEL);
  8045. X        (void)fprintf(stderr, "%s.\n", get_mina());
  8046. X        (void)fprintf(stderr, "Archive/file types recognized:\n");
  8047. X#ifdef BIN
  8048. X        (void)fprintf(stderr,
  8049. X            "\tBinHex 5.0, MacBinary 1.0 and UMCP (with caveat)\n");
  8050. X#endif /* BIN */
  8051. X#ifdef JDW
  8052. X        (void)fprintf(stderr, "\tCompress It\n");
  8053. X#endif /* JDW */
  8054. X#ifdef STF
  8055. X        (void)fprintf(stderr, "\tShrinkToFit\n");
  8056. X#endif /* STF */
  8057. X#ifdef LZC
  8058. X        (void)fprintf(stderr, "\tMacCompress\n");
  8059. X#endif /* LZC */
  8060. X#ifdef ASQ
  8061. X        (void)fprintf(stderr, "\tAutoSqueeze\n");
  8062. X#endif /* ASQ */
  8063. X#ifdef ARC
  8064. X        (void)fprintf(stderr, "\tArcMac\n");
  8065. X#endif /* ARC */
  8066. X#ifdef PIT
  8067. X        (void)fprintf(stderr, "\tPackIt\n");
  8068. X#endif /* PIT */
  8069. X#ifdef SIT
  8070. X        (void)fprintf(stderr, "\tStuffIt and StuffIt Deluxe\n");
  8071. X#endif /* SIT */
  8072. X#ifdef DIA
  8073. X        (void)fprintf(stderr, "\tDiamond\n");
  8074. X#endif /* DIA */
  8075. X#ifdef CPT
  8076. X        (void)fprintf(stderr, "\tCompactor\n");
  8077. X#endif /* CPT */
  8078. X#ifdef ZMA
  8079. X        (void)fprintf(stderr, "\tZoom\n");
  8080. X#endif /* ZMA */
  8081. X#ifdef LZH
  8082. X        (void)fprintf(stderr, "\tMacLHa\n");
  8083. X#endif /* LZH */
  8084. X#ifdef DD
  8085. X        (void)fprintf(stderr, "\tDiskDoubler\n");
  8086. X#endif /* DD */
  8087. X        exit(0);
  8088. X        }
  8089. X    }
  8090. X    }
  8091. X    if(errflg) {
  8092. X    usage();
  8093. X    exit(1);
  8094. X    }
  8095. X
  8096. X    if(optind == argc) {
  8097. X    infp = stdin;
  8098. X    } else {
  8099. X    if((infp = fopen(argv[optind], "r")) == NULL) {
  8100. X        (void)fprintf(stderr,"Can't open input file \"%s\"\n",argv[optind]);
  8101. X        exit(1);
  8102. X    }
  8103. X#ifdef SCAN
  8104. X    do_idf(argv[optind], UNIX_NAME);
  8105. X#endif /* SCAN */
  8106. X    }
  8107. X
  8108. X    if(info_only || verbose || query) {
  8109. X    list++;
  8110. X    }
  8111. X    c = getc(infp);
  8112. X    (void)ungetc(c, infp);
  8113. X    switch(c) {
  8114. X    case 0:
  8115. X    macbinary();
  8116. X    break;
  8117. X#ifdef STF
  8118. X    case 'R':
  8119. X    if(verbose) {
  8120. X        (void)fprintf(stderr, "This is a \"ShrinkToFit\" packed file.\n");
  8121. X    }
  8122. X    stf(~(unsigned long)1);
  8123. X    break;
  8124. X#endif /* STF */
  8125. X#ifdef PIT
  8126. X    case 'P':
  8127. X    if(verbose) {
  8128. X        (void)fprintf(stderr, "This is a \"PackIt\" archive.\n");
  8129. X    }
  8130. X    pit();
  8131. X    break;
  8132. X#endif /* PIT */
  8133. X#ifdef SIT
  8134. X    case 'S':
  8135. X    if(verbose) {
  8136. X        (void)fprintf(stderr, "This is a \"StuffIt\" archive.\n");
  8137. X    }
  8138. X    sit();
  8139. X    break;
  8140. X#endif /* SIT */
  8141. X#ifdef CPT
  8142. X    case 1:
  8143. X    if(verbose) {
  8144. X        (void)fprintf(stderr, "This is a \"Compactor\" archive.\n");
  8145. X    }
  8146. X    cpt();
  8147. X    break;
  8148. X#endif /* CPT */
  8149. X    default:
  8150. X    (void)fprintf(stderr, "Unrecognized archive type\n");
  8151. X    exit(1);
  8152. X    }
  8153. X    exit(0);
  8154. X    /* NOTREACHED */
  8155. X}
  8156. X
  8157. Xstatic void usage()
  8158. X{
  8159. X    (void)fprintf(stderr, "Usage: macunpack [-%s] [filename]\n", options);
  8160. X    (void)fprintf(stderr, "Use \"macunpack -H\" for help.\n");
  8161. X}
  8162. X
  8163. SHAR_EOF
  8164. if test 4173 -ne "`wc -c < 'macunpack.c'`"
  8165. then
  8166.     echo shar: "error transmitting 'macunpack.c'" '(should have been 4173 characters)'
  8167. fi
  8168. fi
  8169. echo shar: "extracting 'macunpack.h'" '(571 characters)'
  8170. if test -f 'macunpack.h'
  8171. then
  8172.     echo shar: "will not over-write existing file 'macunpack.h'"
  8173. else
  8174. sed 's/^X//' << \SHAR_EOF > 'macunpack.h'
  8175. X#define    UNTESTED    /* Know about the untested algorithms */
  8176. X#define    BIN        /* Know about BinHex 5.0 etc. */
  8177. X#define    JDW        /* Know about Compress It */
  8178. X#define    STF        /* Know about ShrinkToFit */
  8179. X#define    LZC        /* Know about MacCompress */
  8180. X#undef    ASQ        /* Know about AutoSqueeze */
  8181. X#undef    ARC        /* Know about ArcMac */
  8182. X#define    PIT        /* Know about PackIt */
  8183. X#define    SIT        /* Know about StuffIt */
  8184. X#define    DIA        /* Know about Diamond */
  8185. X#define    CPT        /* Know about Compactor */
  8186. X#define    ZMA        /* Know about Zoom */
  8187. X#define    LZH        /* Know about LHa */
  8188. X#define    DD        /* Know about DiskDoubler */
  8189. X
  8190. SHAR_EOF
  8191. if test 571 -ne "`wc -c < 'macunpack.h'`"
  8192. then
  8193.     echo shar: "error transmitting 'macunpack.h'" '(should have been 571 characters)'
  8194. fi
  8195. fi
  8196. echo shar: "extracting 'lzh.h'" '(1339 characters)'
  8197. if test -f 'lzh.h'
  8198. then
  8199.     echo shar: "will not over-write existing file 'lzh.h'"
  8200. else
  8201. sed 's/^X//' << \SHAR_EOF > 'lzh.h'
  8202. X#define FILEHDRSIZE    22
  8203. X#define TOTALSIZE    64
  8204. X#define L_HSIZE        0
  8205. X#define L_HCRC        1
  8206. X#define L_METHOD    2
  8207. X#define L_PSIZE        7
  8208. X#define L_UPSIZE    11
  8209. X#define L_LASTMOD    15
  8210. X#define L_ATTRIBUTE    19
  8211. X
  8212. X/* Level 0 and level 1 headers */
  8213. X#define L_NLENGTH    21
  8214. X#define L_NAME        22
  8215. X/* Offset after name */
  8216. X#define L_CRC        0
  8217. X#define L_ETYPE        2
  8218. X#define L_EXTENDSZ    3
  8219. X#define L_EXTEND    4
  8220. X
  8221. X/* Level 2 header */
  8222. X#define L_2CRC        21
  8223. X#define L_2ETYPE    23
  8224. X#define L_2EXTENDSZ    24
  8225. X#define L_2EXTEND    25
  8226. X
  8227. X/* Extension definition, EXTEND defines the size of the extension. */
  8228. X#define L_KIND        0    /* After EXTEND */
  8229. X#define L_ENAME        2    /* Extension name, EXTEND-3 bytes long */
  8230. X/* Offset after name */
  8231. X#define L_EEXTENDSZ    0
  8232. X#define L_EEXTEND    1
  8233. X
  8234. Xtypedef struct fileHdr { /* 58 bytes */
  8235. X    unsigned char    hsize;
  8236. X    unsigned char    hcrc;
  8237. X    char        method[5];
  8238. X    unsigned long    psize;
  8239. X    unsigned long    upsize;
  8240. X    unsigned long    lastmod;
  8241. X    unsigned short    attribute;
  8242. X    unsigned char    nlength;
  8243. X    char        name[32];
  8244. X    unsigned short    crc;
  8245. X    unsigned char    etype;
  8246. X    unsigned char    extendsize;
  8247. X    char        *extend;
  8248. X    char        *data;
  8249. X};
  8250. X
  8251. X/* Currently known methods: */
  8252. X#define    lh0    0
  8253. X#define    lh1    1
  8254. X#define lh2    2
  8255. X#define lh3    3
  8256. X#define lh4    4
  8257. X#define    lh5    5
  8258. X#define lz4    6
  8259. X#define    lz5    7
  8260. X#define    lzs    8
  8261. X
  8262. Xextern char *lzh_pointer;
  8263. Xextern char *lzh_data;
  8264. Xextern char *lzh_finfo;
  8265. Xextern int lzh_fsize;
  8266. Xextern int lzh_kind;
  8267. Xextern char *lzh_file;
  8268. X
  8269. SHAR_EOF
  8270. if test 1339 -ne "`wc -c < 'lzh.h'`"
  8271. then
  8272.     echo shar: "error transmitting 'lzh.h'" '(should have been 1339 characters)'
  8273. fi
  8274. fi
  8275. echo shar: "extracting 'dia.c'" '(13018 characters)'
  8276. if test -f 'dia.c'
  8277. then
  8278.     echo shar: "will not over-write existing file 'dia.c'"
  8279. else
  8280. sed 's/^X//' << \SHAR_EOF > 'dia.c'
  8281. X#include "macunpack.h"
  8282. X#ifdef DIA
  8283. X#include "globals.h"
  8284. X#include "dia.h"
  8285. X#include "../util/curtime.h"
  8286. X#include "../util/masks.h"
  8287. X#include "../fileio/machdr.h"
  8288. X#include "../fileio/wrfile.h"
  8289. X#include "../fileio/kind.h"
  8290. X#include "../util/util.h"
  8291. X
  8292. Xextern char *malloc();
  8293. Xextern char *realloc();
  8294. X
  8295. Xstatic unsigned char *dia_archive;
  8296. Xstatic int dia_archive_size;
  8297. Xstatic int dia_max_archive_size;
  8298. Xstatic int dia_finfo;
  8299. Xstatic int dia_method;
  8300. Xstatic unsigned char *dia_archive_ptr;
  8301. Xstatic unsigned char *dia_header_ptr;
  8302. Xstatic unsigned char *dia_header_last;
  8303. Xstatic int dia_forklength;
  8304. Xstatic int dia_cforklength;
  8305. Xstatic unsigned char dia_bitbuf[BCHUNKSIZE];
  8306. Xstatic int dia_LZtab[BCHUNKSIZE];
  8307. Xstatic unsigned char *dia_bit_base;
  8308. Xstatic int dia_imask;
  8309. X
  8310. Xstatic void dia_folder();
  8311. Xstatic void dia_file();
  8312. Xstatic void dia_getlength();
  8313. Xstatic void dia_skipfork();
  8314. Xstatic void dia_getfork();
  8315. Xstatic void dia_getblock();
  8316. Xstatic int dia_decode();
  8317. Xstatic int dia_prevbit();
  8318. X
  8319. Xvoid dia(bin_hdr)
  8320. Xunsigned char *bin_hdr;
  8321. X{
  8322. X    int i, folder, nlength;
  8323. X    unsigned char hdr;
  8324. X    unsigned char *header;
  8325. X
  8326. X    dir_skip = 0;
  8327. X    for(i = 0; i < INFOBYTES; i++) {
  8328. X    info[i] = 0;
  8329. X    }
  8330. X    if(in_data_size > dia_max_archive_size) {
  8331. X    if(dia_archive == NULL) {
  8332. X        dia_archive = (unsigned char *)malloc((unsigned)in_data_size);
  8333. X    } else {
  8334. X        dia_archive = (unsigned char *)realloc((char *)dia_archive,
  8335. X                           (unsigned)in_data_size);
  8336. X    }
  8337. X    if(dia_archive == 0) {
  8338. X        (void)fprintf(stderr, "Insufficient memory.\n");
  8339. X        exit(1);
  8340. X    }
  8341. X    dia_max_archive_size = in_data_size;
  8342. X    }
  8343. X    dia_archive_size = in_data_size;
  8344. X    if(fread((char *)dia_archive, 1, in_data_size, infp) != in_data_size) {
  8345. X    (void)fprintf(stderr, "Can't read archive.\n");
  8346. X#ifdef SCAN
  8347. X    do_error("macunpack: Can't read archive");
  8348. X#endif /* SCAN */
  8349. X    exit(1);
  8350. X    }
  8351. X    nlength = bin_hdr[I_NAMEOFF] & BYTEMASK;
  8352. X    if(!strncmp((char *)bin_hdr + I_NAMEOFF + nlength - 1, " \272", 2)) {
  8353. X    nlength -= 2;
  8354. X    }
  8355. X    info[I_NAMEOFF] = nlength;
  8356. X    for(i = 1; i <= nlength; i++) {
  8357. X    info[I_NAMEOFF + i] = bin_hdr[I_NAMEOFF + i];
  8358. X    }
  8359. X    hdr = *dia_archive;
  8360. X    folder = hdr & IS_FOLDER;
  8361. X    dia_finfo = hdr & F_INFO;
  8362. X    if(hdr & VOLUME) {
  8363. X    (void)fprintf(stderr, "Multi-segment archives not implemented.\n");
  8364. X#ifdef SCAN
  8365. X    do_error("macunpack: Multi-segment archive");
  8366. X#endif /* SCAN */
  8367. X    exit(1);
  8368. X    }
  8369. X    if(hdr & CRYPTED) {
  8370. X    (void)fprintf(stderr, "Encrypted archives not implemented.\n");
  8371. X#ifdef SCAN
  8372. X    do_idf("", PROTECTED);
  8373. X#endif /* SCAN */
  8374. X    exit(1);
  8375. X    }
  8376. X    i = (hdr & N_BLOCKS) + 1;
  8377. X    header = (unsigned char *)malloc((unsigned)(i * CHUNKSIZE));
  8378. X    dia_archive_ptr = dia_archive + 1;
  8379. X    dia_header_last = header;
  8380. X    dia_method = 0;
  8381. X    while(i-- > 0) {
  8382. X    dia_getblock(&dia_archive_ptr, &dia_header_last);
  8383. X    }
  8384. X    dia_header_ptr = header;
  8385. X    if(folder) {
  8386. X    dia_folder((unsigned char *)NULL);
  8387. X    } else {
  8388. X    dia_file(*dia_header_ptr++, (unsigned char *)NULL);
  8389. X    }
  8390. X    free((char *)header);
  8391. X}
  8392. X
  8393. Xstatic void dia_folder(name)
  8394. Xunsigned char *name;
  8395. X{
  8396. X    unsigned char lname[32];
  8397. X    int i, length, doit;
  8398. X    unsigned char indicator, *old_ptr;
  8399. X
  8400. X    if(name != NULL) {
  8401. X    for(i = 0; i < INFOBYTES; i++) {
  8402. X        info[i] = 0;
  8403. X    }
  8404. X    length = *name++ & REMAINS;
  8405. X    info[I_NAMEOFF] = length;
  8406. X    for(i = 1; i <= length; i++) {
  8407. X        info[I_NAMEOFF + i] = *name++;
  8408. X    }
  8409. X    } else {
  8410. X    length = info[I_NAMEOFF];
  8411. X    }
  8412. X    if(dia_finfo) {
  8413. X    dia_header_ptr += 20;
  8414. X    }
  8415. X    if(!dir_skip) {
  8416. X    doit = 1;
  8417. X    if(list) {
  8418. X        transname(info + I_NAMEOFF + 1, (char *)lname, length);
  8419. X        do_indent(indent);
  8420. X        (void)fprintf(stderr, "folder=\"%s\"", lname);
  8421. X        if(query) {
  8422. X        doit = do_query();
  8423. X        } else {
  8424. X        (void)fputc('\n', stderr);
  8425. X        }
  8426. X        if(doit) {
  8427. X        indent++;
  8428. X        } else {
  8429. X        dir_skip = 1;
  8430. X        }
  8431. X    }
  8432. X    if(doit && !info_only) {
  8433. X        do_mkdir((char *)lname, info);
  8434. X    }
  8435. X    } else {
  8436. X    dir_skip++;
  8437. X    }
  8438. X    while(dia_header_ptr < dia_header_last) {
  8439. X    indicator = *dia_header_ptr;
  8440. X    if(indicator & LEAVE_FOLDER) {
  8441. X        *dia_header_ptr = indicator & ~LEAVE_FOLDER;
  8442. X        break;
  8443. X    } else if(indicator & ONLY_FOLDER) {
  8444. X        if(indicator == ONLY_FOLDER) {
  8445. X        dia_header_ptr++;
  8446. X        } else {
  8447. X        *dia_header_ptr -= 1;
  8448. X        }
  8449. X        break;
  8450. X    } else if(indicator & FOLDER) {
  8451. X        old_ptr = dia_header_ptr;
  8452. X        dia_header_ptr += (indicator & REMAINS) + 1;
  8453. X        dia_folder(old_ptr);
  8454. X    } else {
  8455. X        dia_header_ptr++;
  8456. X        old_ptr = dia_header_ptr;
  8457. X        dia_header_ptr += (*old_ptr & REMAINS) + 1;
  8458. X        dia_file(indicator, old_ptr);
  8459. X    }
  8460. X    }
  8461. X    if(!dir_skip) {
  8462. X    if(doit) {
  8463. X        indent--;
  8464. X        if(!info_only) {
  8465. X        enddir();
  8466. X        }
  8467. X        do_indent(indent);
  8468. X        (void)fprintf(stderr, "leaving folder \"%s\"\n", lname);
  8469. X    }
  8470. X    } else {
  8471. X    dir_skip--;
  8472. X    }
  8473. X}
  8474. X
  8475. Xstatic void dia_file(indicator, name)
  8476. Xunsigned char indicator, *name;
  8477. X{
  8478. X    unsigned char lname[32];
  8479. X    int i, length, doit;
  8480. X    int n_data, n_rsrc;
  8481. X    unsigned char *old_archive_ptr;
  8482. X    char ftype[5], fauth[5];
  8483. X    int dataLength, rsrcLength;
  8484. X    int cdataLength, crsrcLength;
  8485. X    int dataMethod, rsrcMethod;
  8486. X    unsigned long curtime;
  8487. X
  8488. X    if(name != NULL) {
  8489. X    for(i = 0; i < INFOBYTES; i++) {
  8490. X        info[i] = 0;
  8491. X    }
  8492. X    length = *name++ & REMAINS;
  8493. X    info[I_NAMEOFF] = length;
  8494. X    for(i = 1; i <= length; i++) {
  8495. X        info[I_NAMEOFF + i] = *name++;
  8496. X    }
  8497. X    } else {
  8498. X    length = info[I_NAMEOFF];
  8499. X    }
  8500. X    for(i = 0; i < 4; i++) {
  8501. X    info[I_TYPEOFF + i] = *dia_header_ptr++;
  8502. X    }
  8503. X    for(i = 0; i < 4; i++) {
  8504. X    info[I_AUTHOFF + i] = *dia_header_ptr++;
  8505. X    }
  8506. X    if(indicator & DATE_PRESENT) {
  8507. X    for(i = 0; i < 4; i++) {
  8508. X        info[I_CTIMOFF + i] = *dia_header_ptr++;
  8509. X    }
  8510. X    for(i = 0; i < 4; i++) {
  8511. X        info[I_MTIMOFF + i] = *dia_header_ptr++;
  8512. X    }
  8513. X    } else {
  8514. X    curtime = (unsigned long)time((time_t *)0) + TIMEDIFF;
  8515. X    put4(info + I_CTIMOFF, curtime);
  8516. X    put4(info + I_MTIMOFF, curtime);
  8517. X    }
  8518. X    if(dia_finfo) {
  8519. X    for(i = 0; i < 6; i++) {
  8520. X        info[I_FLAGOFF + i] = *dia_header_ptr++;
  8521. X    }
  8522. X    }
  8523. X    n_data = 0;
  8524. X    if(indicator & HAS_DATA) {
  8525. X    if(indicator & SHORT_DATA) {
  8526. X        n_data = 1;
  8527. X    } else {
  8528. X        n_data = *dia_header_ptr++ + 1;
  8529. X    }
  8530. X    }
  8531. X    n_rsrc = 0;
  8532. X    if(indicator & HAS_RSRC) {
  8533. X    if(indicator & SHORT_RSRC) {
  8534. X        n_rsrc = 1;
  8535. X    } else {
  8536. X        n_rsrc = *dia_header_ptr++ + 1;
  8537. X    }
  8538. X    }
  8539. X    if(!dir_skip) {
  8540. X    old_archive_ptr = dia_archive_ptr;
  8541. X    dia_getlength(n_data);
  8542. X    dataLength = dia_forklength;
  8543. X    cdataLength = dia_cforklength;
  8544. X    dataMethod = dia_method;
  8545. X    dia_getlength(n_rsrc);
  8546. X    rsrcLength = dia_forklength;
  8547. X    crsrcLength = dia_cforklength;
  8548. X    rsrcMethod = dia_method;
  8549. X    dia_archive_ptr = old_archive_ptr;
  8550. X    put4(info + I_DLENOFF, (unsigned long)dataLength);
  8551. X    put4(info + I_RLENOFF, (unsigned long)rsrcLength);
  8552. X    if(list) {
  8553. X        transname(info + I_NAMEOFF + 1, (char *)lname, length);
  8554. X        do_indent(indent);
  8555. X        transname(info + I_TYPEOFF, ftype, 4);
  8556. X        transname(info + I_AUTHOFF, fauth, 4);
  8557. X        (void)fprintf(stderr,
  8558. X            "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  8559. X            lname, ftype, fauth, (long)dataLength, (long)rsrcLength);
  8560. X        if(info_only) {
  8561. X        doit = 0;
  8562. X        } else {
  8563. X        doit = 1;
  8564. X        }
  8565. X        if(query) {
  8566. X        doit = do_query();
  8567. X        } else {
  8568. X        (void)fputc('\n', stderr);
  8569. X        }
  8570. X    } else {
  8571. X        doit = 1;
  8572. X    }
  8573. X    } else {
  8574. X    dia_skipfork(n_data);
  8575. X    dia_skipfork(n_rsrc);
  8576. X    return;
  8577. X    }
  8578. X    if(doit) {
  8579. X    define_name((char *)lname);
  8580. X    start_info(info, (unsigned long)rsrcLength, (unsigned long)dataLength);
  8581. X    }
  8582. X    if(verbose) {
  8583. X    (void)fprintf(stderr, "\tData: ");
  8584. X    if(dataLength == 0) {
  8585. X        (void)fprintf(stderr, "empty");
  8586. X    } else if(dataMethod == NOCOMP) {
  8587. X        (void)fprintf(stderr, "No compression");
  8588. X    } else {
  8589. X        if(dataMethod != COMP) {
  8590. X        (void)fprintf(stderr, "Partial ");
  8591. X        }
  8592. X        (void)fprintf(stderr, "LZFK compressed (%4.1f%%)",
  8593. X        100.0 * cdataLength / dataLength);
  8594. X    }
  8595. X    }
  8596. X    if(doit) {
  8597. X    start_data();
  8598. X    dia_getfork(n_data);
  8599. X    } else {
  8600. X    dia_skipfork(n_data);
  8601. X    }
  8602. X    if(verbose) {
  8603. X    (void)fprintf(stderr, ", Rsrc: ");
  8604. X    if(rsrcLength == 0) {
  8605. X        (void)fprintf(stderr, "empty");
  8606. X    } else if(rsrcMethod == NOCOMP) {
  8607. X        (void)fprintf(stderr, "No compression");
  8608. X    } else {
  8609. X        if(rsrcMethod != COMP) {
  8610. X        (void)fprintf(stderr, "Partial ");
  8611. X        }
  8612. X        (void)fprintf(stderr, "LZFK compressed (%4.1f%%)",
  8613. X        100.0 * crsrcLength / rsrcLength);
  8614. X    }
  8615. X    }
  8616. X    if(doit) {
  8617. X    start_rsrc();
  8618. X    dia_getfork(n_rsrc);
  8619. X    } else {
  8620. X    dia_skipfork(n_rsrc);
  8621. X    }
  8622. X    if(verbose) {
  8623. X    (void)fprintf(stderr, ".\n");
  8624. X    }
  8625. X    if(doit) {
  8626. X    end_file();
  8627. X    }
  8628. X}
  8629. X
  8630. Xstatic void dia_getlength(nblocks)
  8631. Xint nblocks;
  8632. X{
  8633. X    int length;
  8634. X    unsigned char *arch_ptr, *block_ptr;
  8635. X    unsigned char block[CHUNKSIZE];
  8636. X
  8637. X    dia_method = 0;
  8638. X    dia_forklength = 0;
  8639. X    dia_cforklength = 0;
  8640. X    while(nblocks > 1) {
  8641. X    nblocks--;
  8642. X    length = get2((char *)dia_archive_ptr);
  8643. X    if(length >= 0x8000) {
  8644. X        length = 0x10000 - length;
  8645. X        dia_method |= NOCOMP;
  8646. X    } else {
  8647. X        dia_method |= COMP;
  8648. X    }
  8649. X    dia_forklength += CHUNKSIZE;
  8650. X    dia_cforklength += length + 2;
  8651. X    dia_archive_ptr += length + 2;
  8652. X    }
  8653. X    if(nblocks == 1) {
  8654. X    arch_ptr = dia_archive_ptr;
  8655. X    block_ptr = block;
  8656. X    dia_getblock(&arch_ptr, &block_ptr);
  8657. X    dia_forklength += block_ptr - block;
  8658. X    dia_cforklength += arch_ptr - dia_archive_ptr;
  8659. X    dia_archive_ptr = arch_ptr;
  8660. X    }
  8661. X}
  8662. X
  8663. Xstatic void dia_skipfork(nblocks)
  8664. Xint nblocks;
  8665. X{
  8666. X    int length;
  8667. X
  8668. X    while(nblocks-- > 0) {
  8669. X    length = get2((char *)dia_archive_ptr);
  8670. X    if(length >= 0x8000) {
  8671. X        length = 0x10000 - length;
  8672. X    }
  8673. X    dia_archive_ptr += length + 2;
  8674. X    }
  8675. X}
  8676. X
  8677. Xstatic void dia_getfork(nblocks)
  8678. Xint nblocks;
  8679. X{
  8680. X    while(nblocks-- > 0) {
  8681. X    dia_getblock(&dia_archive_ptr, (unsigned char **)&out_ptr);
  8682. X    }
  8683. X}
  8684. X
  8685. Xstatic void dia_getblock(archive_ptr, block_ptr)
  8686. Xunsigned char **archive_ptr, **block_ptr;
  8687. X{
  8688. X    int length, i;
  8689. X    unsigned char *arch_ptr, *bl_ptr;
  8690. X
  8691. X    arch_ptr = *archive_ptr;
  8692. X    bl_ptr = *block_ptr;
  8693. X    length = get2((char *)arch_ptr);
  8694. X    arch_ptr += 2;
  8695. X    if(length >= 0x8000) {
  8696. X    length = 0x10000 - length;
  8697. X    for(i = 0; i < length; i++) {
  8698. X        *bl_ptr++ = *arch_ptr++;
  8699. X    }
  8700. X    *block_ptr += length;
  8701. X    dia_method |= NOCOMP;
  8702. X    } else {
  8703. X    *block_ptr += dia_decode(arch_ptr, bl_ptr, length);
  8704. X    dia_method |= COMP;
  8705. X    }
  8706. X    *archive_ptr += length + 2;
  8707. X}
  8708. X
  8709. Xstatic int dia_decode(ibuff, obuff, in_length)
  8710. Xunsigned char *ibuff, *obuff; int in_length;
  8711. X{
  8712. X    int nbits, set_zero, i, j;
  8713. X    unsigned char *bitbuf_ptr;
  8714. X    int count[4];
  8715. X    int *LZtab_ptr;
  8716. X    unsigned char *out_ptr, *buf_ptr, *in_ptr;
  8717. X    int omask;
  8718. X    int LZcount;
  8719. X    int *length_ptr, *nchars_ptr;
  8720. X    int *offsn_ptr, length, nchars, offset;
  8721. X    int *offs_ptr[4];
  8722. X    int nwords;
  8723. X
  8724. X    in_ptr = ibuff + in_length;
  8725. X    nbits = *--in_ptr;
  8726. X    nbits |= (*--in_ptr << 8);
  8727. X    if(nbits == WORDMASK) {
  8728. X    nbits = *--in_ptr;
  8729. X    nbits |= (*--in_ptr << 8);
  8730. X    nbits = nbits + WORDMASK;
  8731. X    }
  8732. X    bitbuf_ptr = dia_bitbuf + BCHUNKSIZE;
  8733. X    *--bitbuf_ptr = *--in_ptr;
  8734. X    set_zero = 0;
  8735. X    dia_bit_base = bitbuf_ptr;
  8736. X    dia_imask = 1 << (7 - (nbits & 7));
  8737. X    if(dia_prevbit()) {
  8738. X    set_zero = 1;
  8739. X    }
  8740. X    for(i = 0; i < nbits; i++) {
  8741. X    if(set_zero) {
  8742. X        *--bitbuf_ptr = 0;
  8743. X    } else {
  8744. X        *--bitbuf_ptr = *--in_ptr;
  8745. X    }
  8746. X    if(dia_prevbit()) {
  8747. X        set_zero = !set_zero;
  8748. X    }
  8749. X    }
  8750. X    /* Now we have the bits in longitudal order; reorder them */
  8751. X    nwords = ((dia_bit_base - bitbuf_ptr) >> 1);
  8752. X    for(i = 0; i < nwords; i++) {
  8753. X    dia_LZtab[i] = 0;
  8754. X    }
  8755. X    omask = 1;
  8756. X    for(i = 0; i < 16; i++) {
  8757. X    j = nwords;
  8758. X    LZtab_ptr = dia_LZtab + nwords;
  8759. X    while(j-- > 0) {
  8760. X        LZtab_ptr--;
  8761. X        if(dia_prevbit()) {
  8762. X        *LZtab_ptr |= omask;
  8763. X        }
  8764. X    }
  8765. X    omask <<= 1;
  8766. X    }
  8767. X    LZcount = nwords / 3;
  8768. X    /*  At this point we have in LZtab LZcount triples.  Each triple consists
  8769. X    of the following parts:
  8770. X        nchars:    the number of characters to take from input
  8771. X        length:    the number of characters - 1 to copy from output
  8772. X        offset:    the offset in the output buffer
  8773. X    The ordering is as follows:
  8774. X    1.    lengths
  8775. X    2.    nchars
  8776. X    3.    offsets for length 0
  8777. X    4.    offsets for length 1
  8778. X    5.    offsets for length 2
  8779. X    6.    offsets for length 3
  8780. X    7.    offsets for other lengths
  8781. X    */
  8782. X    /*    Now first count the occurences of lengths 0 to 3 */
  8783. X    count[0] = 0;
  8784. X    count[1] = 0;
  8785. X    count[2] = 0;
  8786. X    count[3] = 0;
  8787. X    for(i = 0; i < LZcount; i++) {
  8788. X    if((j = dia_LZtab[i]) < 4) {
  8789. X        count[j]++;
  8790. X    }
  8791. X    }
  8792. X    length_ptr = dia_LZtab;
  8793. X    nchars_ptr = dia_LZtab + LZcount;
  8794. X    offs_ptr[0] = nchars_ptr + LZcount;
  8795. X    offs_ptr[1] = offs_ptr[0] + count[0];
  8796. X    offs_ptr[2] = offs_ptr[1] + count[1];
  8797. X    offs_ptr[3] = offs_ptr[2] + count[2];
  8798. X    offsn_ptr = offs_ptr[3] + count[3];
  8799. X    out_ptr = obuff;
  8800. X    for(i = 0; i < LZcount; i++) {
  8801. X    length = *length_ptr++;
  8802. X    nchars = *nchars_ptr++;
  8803. X    if(length < 4) {
  8804. X        offset = *offs_ptr[length]++;
  8805. X    } else {
  8806. X        offset = *offsn_ptr++;
  8807. X    }
  8808. X    while(nchars-- > 0) {
  8809. X        *out_ptr++ = *ibuff++;
  8810. X    }
  8811. X    buf_ptr = out_ptr - length - offset - 1;
  8812. X    while(length-- >= 0) {
  8813. X        *out_ptr++ = *buf_ptr++;
  8814. X    }
  8815. X    }
  8816. X    i = in_ptr - ibuff;
  8817. X    while(i-- > 0) {
  8818. X    *out_ptr++ = *ibuff++;
  8819. X    }
  8820. X    return out_ptr - obuff;
  8821. X}
  8822. X
  8823. Xstatic int dia_prevbit()
  8824. X{
  8825. X    int c;
  8826. X
  8827. X    if(dia_imask == 0x100) {
  8828. X    dia_bit_base--;
  8829. X    dia_imask = 1;
  8830. X    }
  8831. X    c = *dia_bit_base & dia_imask;
  8832. X    dia_imask <<= 1;
  8833. X    return c;
  8834. X}
  8835. X#else /* DIA */
  8836. Xint dia; /* keep lint and some compilers happy */
  8837. X#endif /* DIA */
  8838. X
  8839. SHAR_EOF
  8840. if test 13018 -ne "`wc -c < 'dia.c'`"
  8841. then
  8842.     echo shar: "error transmitting 'dia.c'" '(should have been 13018 characters)'
  8843. fi
  8844. fi
  8845. echo shar: "extracting 'de_huffman.c'" '(2547 characters)'
  8846. if test -f 'de_huffman.c'
  8847. then
  8848.     echo shar: "will not over-write existing file 'de_huffman.c'"
  8849. else
  8850. sed 's/^X//' << \SHAR_EOF > 'de_huffman.c'
  8851. X#include "macunpack.h"
  8852. X#ifdef JDW
  8853. X#define DEHUFFMAN
  8854. X#endif /* JDW */
  8855. X#ifdef STF
  8856. X#define DEHUFFMAN
  8857. X#endif /* STF */
  8858. X#ifdef PIT
  8859. X#define DEHUFFMAN
  8860. X#endif /* PIT */
  8861. X#ifdef SIT
  8862. X#define DEHUFFMAN
  8863. X#endif /* SIT */
  8864. X#ifdef CPT
  8865. X#define DEHUFFMAN
  8866. X#endif /* CPT */
  8867. X#ifdef DEHUFFMAN
  8868. X#include "globals.h"
  8869. X#include "../util/masks.h"
  8870. X#include "../fileio/wrfile.h"
  8871. X#include "huffman.h"
  8872. X#include "../util/util.h"
  8873. X
  8874. Xint (*get_bit)();
  8875. Xint bytesread;
  8876. X/* 515 because StuffIt Classic needs more than the needed 511 */
  8877. Xstruct node nodelist[515];
  8878. Xstatic int getbit_be();
  8879. Xstatic int getbit_le();
  8880. Xstatic int getdecodebyte();
  8881. X
  8882. Xstatic node *nodeptr, *read_sub_tree();
  8883. X
  8884. Xstatic int bit;
  8885. X
  8886. Xvoid de_huffman(obytes)
  8887. Xunsigned long obytes;
  8888. X{
  8889. X    while(obytes != 0) {
  8890. X    *out_ptr++ = gethuffbyte(nodelist);
  8891. X    obytes--;
  8892. X    }
  8893. X    return;
  8894. X}
  8895. X
  8896. Xvoid de_huffman_end(term)
  8897. Xunsigned int term;
  8898. X{
  8899. X    int c;
  8900. X
  8901. X    while((c = gethuffbyte(nodelist)) != term) {
  8902. X    *out_ptr++ = c;
  8903. X    }
  8904. X}
  8905. X
  8906. Xvoid set_huffman(endian)
  8907. Xint endian;
  8908. X{
  8909. X    if(endian == HUFF_LE) {
  8910. X    get_bit = getbit_le;
  8911. X    } else if(endian == HUFF_BE) {
  8912. X    get_bit = getbit_be;
  8913. X    }
  8914. X}
  8915. X
  8916. Xvoid read_tree()
  8917. X{
  8918. X    nodeptr = nodelist;
  8919. X    bit = 0;        /* put us on a boundary */
  8920. X    (void)read_sub_tree();
  8921. X}
  8922. X
  8923. X/* This routine recursively reads the Huffman encoding table and builds
  8924. X   a decoding tree. */
  8925. Xstatic node *read_sub_tree()
  8926. X{
  8927. X    node *np;
  8928. X
  8929. X    np = nodeptr++;
  8930. X    if((*get_bit)() == 1) {
  8931. X    np->flag = 1;
  8932. X    np->byte = getdecodebyte();
  8933. X    } else {
  8934. X    np->flag = 0;
  8935. X    np->zero = read_sub_tree();
  8936. X    np->one  = read_sub_tree();
  8937. X    }
  8938. X    return np;
  8939. X}
  8940. X
  8941. X/* This routine returns the next bit in the input stream (MSB first) */
  8942. Xstatic int getbit_be()
  8943. X{
  8944. X    static int b;
  8945. X
  8946. X    if(bit == 0) {
  8947. X    b = getb(infp) & BYTEMASK;
  8948. X    bit = 8;
  8949. X    bytesread++;
  8950. X    }
  8951. X    bit--;
  8952. X    return (b >> bit) & 1;
  8953. X}
  8954. X
  8955. X/* This routine returns the next bit in the input stream (LSB first) */
  8956. Xstatic int getbit_le()
  8957. X{
  8958. X    static int b;
  8959. X
  8960. X    if(bit == 0) {
  8961. X    b = getb(infp) & BYTEMASK;
  8962. X    bit = 8;
  8963. X    bytesread++;
  8964. X    }
  8965. X    bit--;
  8966. X    return (b >> (7 - bit)) & 1;
  8967. X}
  8968. X
  8969. Xvoid clrhuff()
  8970. X{
  8971. X    bit = 0;
  8972. X}
  8973. X
  8974. Xint gethuffbyte(l_nodelist)
  8975. Xnode *l_nodelist;
  8976. X{
  8977. X    register node *np;
  8978. X
  8979. X    np = l_nodelist;
  8980. X    while(np->flag == 0) {
  8981. X    np = (*get_bit)() ? np->one : np->zero;
  8982. X    }
  8983. X    return np->byte;
  8984. X}
  8985. X
  8986. Xint getihuffbyte()
  8987. X{
  8988. X    return gethuffbyte(nodelist);
  8989. X}
  8990. X
  8991. Xstatic int getdecodebyte()
  8992. X{
  8993. X    register int i, b;
  8994. X
  8995. X    b = 0;
  8996. X    for(i = 8; i > 0; i--) {
  8997. X    b = (b << 1) + (*get_bit)();
  8998. X    }
  8999. X    return b;
  9000. X}
  9001. X#else /* DEHUFFMAN */
  9002. Xint dehuffman; /* keep lint and some compilers happy */
  9003. X#endif /* DEHUFFMAN */
  9004. X
  9005. SHAR_EOF
  9006. if test 2547 -ne "`wc -c < 'de_huffman.c'`"
  9007. then
  9008.     echo shar: "error transmitting 'de_huffman.c'" '(should have been 2547 characters)'
  9009. fi
  9010. fi
  9011. echo shar: "extracting 'de_compress.c'" '(5169 characters)'
  9012. if test -f 'de_compress.c'
  9013. then
  9014.     echo shar: "will not over-write existing file 'de_compress.c'"
  9015. else
  9016. sed 's/^X//' << \SHAR_EOF > 'de_compress.c'
  9017. X#include "macunpack.h"
  9018. X#ifdef SIT
  9019. X#define DECOMPRESS
  9020. X#endif /* SIT */
  9021. X#ifdef LZC
  9022. X#define DECOMPRESS
  9023. X#endif /* LZC */
  9024. X#ifdef DECOMPRESS
  9025. X#include "globals.h"
  9026. X#include "../fileio/wrfile.h"
  9027. X
  9028. X/* Written to allow for bits to be upto 16, MacCompress can use 16 bits */
  9029. X
  9030. X#define    BITS    16
  9031. X#define HSIZE    69001        /* 95% occupancy */
  9032. X
  9033. X#define INIT_BITS 9            /* initial number of bits/code */
  9034. X
  9035. Xstatic int n_bits;                /* number of bits/code */
  9036. Xstatic int maxbits;            /* user settable max # bits/code */
  9037. Xstatic long maxcode;            /* maximum code, given n_bits */
  9038. Xstatic long maxmaxcode;            /* should NEVER generate this code */
  9039. X# define MAXCODE(n_bits)    ((1 << (n_bits)) - 1)
  9040. X
  9041. Xstatic long htab [HSIZE];
  9042. Xstatic unsigned short codetab [HSIZE];
  9043. X
  9044. X#define tab_prefixof(i) codetab[i]
  9045. X#define tab_suffixof(i)    ((unsigned char *)(htab))[i]
  9046. X#define de_stack    ((unsigned char *)&tab_suffixof(1<<BITS))
  9047. X
  9048. Xstatic long free_ent = 0;            /* first unused entry */
  9049. X
  9050. Xstatic long getcode();
  9051. X
  9052. Xstatic int clear_flg = 0;
  9053. X
  9054. X/*
  9055. X * the next two codes should not be changed lightly, as they must not
  9056. X * lie within the contiguous general code space.
  9057. X */
  9058. X#define FIRST    257    /* first free entry */
  9059. X#define    CLEAR    256    /* table clear output code */
  9060. X
  9061. Xstatic int toread;
  9062. X
  9063. Xvoid de_compress(ibytes, mb)
  9064. Xunsigned long ibytes;
  9065. Xint mb;
  9066. X{
  9067. X    register unsigned char *stackp;
  9068. X    register int finchar;
  9069. X    register long code, oldcode, incode;
  9070. X
  9071. X    toread = ibytes;
  9072. X    maxbits = mb;
  9073. X    maxmaxcode = 1 << maxbits;
  9074. X    maxcode = MAXCODE(n_bits = INIT_BITS);
  9075. X    for(code = 255; code >= 0; code--) {
  9076. X    tab_prefixof(code) = 0;
  9077. X    tab_suffixof(code) = (unsigned char)code;
  9078. X    }
  9079. X    free_ent = FIRST;
  9080. X    finchar = oldcode = getcode();
  9081. X    if(oldcode == -1) {    /* EOF already? */
  9082. X    return;            /* Get out of here */
  9083. X    }
  9084. X    /* first code must be 8 bits = char */
  9085. X    *out_ptr++ = (char)finchar;
  9086. X    stackp = de_stack;
  9087. X    while((code = getcode()) > -1) {
  9088. X    if(code == CLEAR) {
  9089. X        for(code = 255; code >= 0; code--) {
  9090. X        tab_prefixof(code) = 0;
  9091. X        }
  9092. X        clear_flg = 1;
  9093. X        free_ent = FIRST - 1;
  9094. X        if((code = getcode()) == -1) {    /* O, untimely death! */
  9095. X        break;
  9096. X        }
  9097. X    }
  9098. X    incode = code;
  9099. X    /*
  9100. X     * Special case for KwKwK string.
  9101. X     */
  9102. X    if(code >= free_ent) {
  9103. X        *stackp++ = finchar;
  9104. X        code = oldcode;
  9105. X    }
  9106. X    /*
  9107. X     * Generate output characters in reverse order
  9108. X     */
  9109. X    while(code >= 256) {
  9110. X        *stackp++ = tab_suffixof(code);
  9111. X        code = tab_prefixof(code);
  9112. X    }
  9113. X    *stackp++ = finchar = tab_suffixof(code);
  9114. X    /*
  9115. X     * And put them out in forward order
  9116. X     */
  9117. X    do {
  9118. X        *out_ptr++ = (char)*--stackp;
  9119. X    } while(stackp > de_stack);
  9120. X    /*
  9121. X     * Generate the new entry.
  9122. X     */
  9123. X    if((code=free_ent) < maxmaxcode) {
  9124. X        tab_prefixof(code) = (unsigned short)oldcode;
  9125. X        tab_suffixof(code) = finchar;
  9126. X        free_ent = code+1;
  9127. X    }
  9128. X    /*
  9129. X     * Remember previous code.
  9130. X     */
  9131. X    oldcode = incode;
  9132. X    }
  9133. X    return;
  9134. X}
  9135. X
  9136. Xstatic unsigned char rmask[9] =
  9137. X    {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
  9138. X
  9139. Xstatic int get_core_bytes;
  9140. Xstatic char *core_ptr;
  9141. Xstatic int file_bytes();
  9142. Xstatic int core_bytes();
  9143. X
  9144. Xstatic long getcode()
  9145. X{
  9146. X    register long code;
  9147. X    static int offset = 0, size = 0;
  9148. X    static unsigned char buf[BITS];
  9149. X    register int r_off, bits;
  9150. X    register unsigned char *bp = buf;
  9151. X
  9152. X    if(clear_flg > 0 || offset >= size || free_ent > maxcode) {
  9153. X    /*
  9154. X     * If the next entry will be too big for the current code
  9155. X     * size, then we must increase the size.  This implies reading
  9156. X     * a new buffer full, too.
  9157. X     */
  9158. X    if(free_ent > maxcode) {
  9159. X        n_bits++;
  9160. X        if(n_bits == maxbits) {
  9161. X        maxcode = maxmaxcode;    /* won't get any bigger now */
  9162. X        } else {
  9163. X        maxcode = MAXCODE(n_bits);
  9164. X        }
  9165. X    }
  9166. X    if(clear_flg > 0) {
  9167. X        maxcode = MAXCODE (n_bits = INIT_BITS);
  9168. X        clear_flg = 0;
  9169. X    }
  9170. X    if(toread == 0) {
  9171. X        return -1;
  9172. X    }
  9173. X    if(get_core_bytes) {
  9174. X        size = core_bytes((char *)buf, (n_bits < toread ? n_bits : toread));
  9175. X    } else {
  9176. X        size = file_bytes((char *)buf, (n_bits < toread ? n_bits : toread));
  9177. X    }
  9178. X    toread -= size;
  9179. X    if(size <= 0) {
  9180. X        (void)fprintf(stderr, "Premature EOF\n");
  9181. X#ifdef SCAN
  9182. X        do_error("macunpack: Premature EOF");
  9183. X#endif /* SCAN */
  9184. X        exit(1);
  9185. X    }
  9186. X    offset = 0;
  9187. X    /* Round size down to integral number of codes */
  9188. X    size = (size << 3) - (n_bits - 1);
  9189. X    }
  9190. X    r_off = offset;
  9191. X    bits = n_bits;
  9192. X    /*
  9193. X     * Get to the first byte.
  9194. X     */
  9195. X    bp += (r_off >> 3);
  9196. X    r_off &= 7;
  9197. X    /* Get first part (low order bits) */
  9198. X    code = (*bp++ >> r_off);
  9199. X    bits -= (8 - r_off);
  9200. X    r_off = 8 - r_off;        /* now, offset into code word */
  9201. X    /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
  9202. X    if(bits >= 8) {
  9203. X    code |= *bp++ << r_off;
  9204. X    r_off += 8;
  9205. X    bits -= 8;
  9206. X    }
  9207. X    /* high order bits. */
  9208. X    code |= (*bp & rmask[bits]) << r_off;
  9209. X    offset += n_bits;
  9210. X    return code;
  9211. X}
  9212. X
  9213. Xstatic int file_bytes(buf, length)
  9214. Xchar *buf;
  9215. Xint length;
  9216. X{
  9217. X    return fread(buf, 1, length, infp);
  9218. X}
  9219. X
  9220. Xstatic int core_bytes(buf, length)
  9221. Xchar *buf;
  9222. Xint length;
  9223. X{
  9224. X    int i;
  9225. X
  9226. X    for(i = 0; i < length; i++) {
  9227. X    *buf++ = *core_ptr++;
  9228. X    }
  9229. X    return length;
  9230. X}
  9231. X
  9232. Xvoid core_compress(ptr)
  9233. Xchar *ptr;
  9234. X{
  9235. X    core_ptr = ptr;
  9236. X    get_core_bytes = ptr != NULL;
  9237. X}
  9238. X#else /* DECOMPRESS */
  9239. Xint decompress; /* keep lint and some compilers happy */
  9240. X#endif /* DECOMPRESS */
  9241. X
  9242. SHAR_EOF
  9243. if test 5169 -ne "`wc -c < 'de_compress.c'`"
  9244. then
  9245.     echo shar: "error transmitting 'de_compress.c'" '(should have been 5169 characters)'
  9246. fi
  9247. fi
  9248. echo shar: "extracting 'dia.h'" '(423 characters)'
  9249. if test -f 'dia.h'
  9250. then
  9251.     echo shar: "will not over-write existing file 'dia.h'"
  9252. else
  9253. sed 's/^X//' << \SHAR_EOF > 'dia.h'
  9254. X#define    IS_FOLDER    0x80
  9255. X#define    F_INFO        0x40
  9256. X#define VOLUME        0x30
  9257. X#define    CRYPTED        0x08
  9258. X#define N_BLOCKS    0x07
  9259. X
  9260. X#define    LEAVE_FOLDER    0x80
  9261. X#define    ONLY_FOLDER    0x40
  9262. X#define    FOLDER        0x20
  9263. X#define    DATE_PRESENT    0x10
  9264. X#define    HAS_DATA    0x08
  9265. X#define    HAS_RSRC    0x04
  9266. X#define    SHORT_DATA    0x02
  9267. X#define    SHORT_RSRC    0x01
  9268. X#define    REMAINS        0x1f
  9269. X
  9270. X#define CHUNKSIZE    32767
  9271. X#define BCHUNKSIZE    (CHUNKSIZE * 16 / 7)
  9272. X
  9273. X#define    NOCOMP        1
  9274. X#define COMP        2
  9275. X
  9276. SHAR_EOF
  9277. if test 423 -ne "`wc -c < 'dia.h'`"
  9278. then
  9279.     echo shar: "error transmitting 'dia.h'" '(should have been 423 characters)'
  9280. fi
  9281. fi
  9282. echo shar: "extracting 'arc.h'" '(1196 characters)'
  9283. if test -f 'arc.h'
  9284. then
  9285.     echo shar: "will not over-write existing file 'arc.h'"
  9286. else
  9287. sed 's/^X//' << \SHAR_EOF > 'arc.h'
  9288. X#define    MAGIC1        0    /* Should be 0x1b, marks Mac extension */
  9289. X#define    KIND        1    /* KIND == 0 marks end of archive */
  9290. X#define    FNAME        2
  9291. X#define    FILLER        33
  9292. X#define    FTYPE        34
  9293. X#define    FAUTH        38
  9294. X#define    FINFO        42
  9295. X#define    FDATA        50
  9296. X#define    FRSRC        54
  9297. X#define    FILLER        58
  9298. X#define    MAGIC2        59    /* Should be 0x1a, true Arc header start */
  9299. X#define    KIND2        60    /* Should be identical to KIND */
  9300. X#define    FNAME2        61    /* A PC-ified version of the filename */
  9301. X#define    SIZE        74
  9302. X#define    DATE        78
  9303. X#define    TIME        80
  9304. X#define    CRC        82
  9305. X#define    SIZE2        84    /* Not present if KIND == 1 */
  9306. X#define    HEADERBYTES    88
  9307. X
  9308. Xtypedef struct fileHdr { /* 84 or 88 bytes */
  9309. X    char        magic1;
  9310. X    char        kind;
  9311. X    char        fname[31];
  9312. X    char        filler;        /* ??? */
  9313. X    char        ftype[4];
  9314. X    char        fauth[4];
  9315. X    char        finfo[8];
  9316. X    unsigned long    dataLength;
  9317. X    unsigned long    rsrcLength;
  9318. X    char        filler;
  9319. X    char        magic2;
  9320. X    char        kind2;
  9321. X    char        fname2[13];
  9322. X    unsigned long    size;
  9323. X    unsigned short    date;
  9324. X    unsigned short    time;
  9325. X    unsigend short    crc;
  9326. X    unsigned long    size2;    /* Identical to size; this is wrong for Arc! */
  9327. X};
  9328. X
  9329. X#define    smallstored    1
  9330. X#define    stored        2
  9331. X#define    packed        3
  9332. X#define    squeezed    4
  9333. X#define    crunched1    5
  9334. X#define    crunched2    6
  9335. X#define    crunched3    7
  9336. X#define    crunched4    8
  9337. X#define    squashed    9
  9338. X
  9339. SHAR_EOF
  9340. if test 1196 -ne "`wc -c < 'arc.h'`"
  9341. then
  9342.     echo shar: "error transmitting 'arc.h'" '(should have been 1196 characters)'
  9343. fi
  9344. fi
  9345. echo shar: "extracting 'jdw.c'" '(3552 characters)'
  9346. if test -f 'jdw.c'
  9347. then
  9348.     echo shar: "will not over-write existing file 'jdw.c'"
  9349. else
  9350. sed 's/^X//' << \SHAR_EOF > 'jdw.c'
  9351. X#include "macunpack.h"
  9352. X#ifdef JDW
  9353. X#include "jdw.h"
  9354. X#include "globals.h"
  9355. X#include "huffman.h"
  9356. X#include "../fileio/wrfile.h"
  9357. X#include "../fileio/machdr.h"
  9358. X#include "../util/util.h"
  9359. X#include "../util/masks.h"
  9360. X
  9361. Xextern void de_huffman();
  9362. Xextern void set_huffman();
  9363. Xextern void read_tree();
  9364. Xextern void clrhuff();
  9365. X
  9366. Xstatic void jdw_wrfile();
  9367. Xstatic void jdw_wrfork();
  9368. Xstatic void jdw_block();
  9369. X
  9370. Xvoid jdw(ibytes)
  9371. Xunsigned long ibytes;
  9372. X{
  9373. X    char fauth[5], ftype[5];
  9374. X    int filel, i;
  9375. X    unsigned int rsrcLength, dataLength;
  9376. X
  9377. X    set_huffman(HUFF_BE);
  9378. X    for(i = 0; i < 6; i++) (void)getb(infp);
  9379. X    for(i = 0; i < INFOBYTES; i++) {
  9380. X    info[i] = 0;
  9381. X    }
  9382. X    for(i = 0; i < 4; i++) {
  9383. X    info[I_TYPEOFF + i] = getb(infp);
  9384. X    }
  9385. X    for(i = 0; i < 4; i++) {
  9386. X    info[I_AUTHOFF + i] = getb(infp);
  9387. X    }
  9388. X    for(i = 0; i < 8; i++) {
  9389. X    info[I_FLAGOFF + i] = getb(infp);
  9390. X    }
  9391. X    for(i = 0; i < 4; i++) {
  9392. X    info[I_DLENOFF + i] = getb(infp);
  9393. X    }
  9394. X    for(i = 0; i < 4; i++) {
  9395. X    info[I_RLENOFF + i] = getb(infp);
  9396. X    }
  9397. X    for(i = 0; i < 4; i++) {
  9398. X    info[I_CTIMOFF + i] = getb(infp);
  9399. X    }
  9400. X    for(i = 0; i < 4; i++) {
  9401. X    info[I_MTIMOFF + i] = getb(infp);
  9402. X    }
  9403. X    filel = getb(infp);
  9404. X    info[I_NAMEOFF] = filel;
  9405. X    i = filel;
  9406. X    for(i = 1; i <= filel; i++) {
  9407. X    info[I_NAMEOFF + i] = getb(infp);
  9408. X    }
  9409. X    (void)getb(infp);
  9410. X    rsrcLength = get4(info + I_RLENOFF);
  9411. X    dataLength = get4(info + I_DLENOFF);
  9412. X    ibytes -= filel + 40;
  9413. X    write_it = 1;
  9414. X    if(list) {
  9415. X    transname(info + I_NAMEOFF + 1, text, (int)info[I_NAMEOFF]);
  9416. X    transname(info + I_TYPEOFF, ftype, 4);
  9417. X    transname(info + I_AUTHOFF, fauth, 4);
  9418. X    do_indent(indent);
  9419. X    (void)fprintf(stderr,
  9420. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  9421. X        text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  9422. X    if(info_only) {
  9423. X        write_it = 0;
  9424. X    }
  9425. X    if(query) {
  9426. X        write_it = do_query();
  9427. X    } else {
  9428. X        (void)fputc('\n', stderr);
  9429. X    }
  9430. X    }
  9431. X    jdw_wrfile((unsigned long)rsrcLength, (unsigned long)dataLength);
  9432. X}
  9433. X
  9434. Xstatic void jdw_wrfile(rsrcLength, dataLength)
  9435. Xunsigned long rsrcLength, dataLength;
  9436. X{
  9437. X    if(write_it) {
  9438. X    define_name(text);
  9439. X    start_info(info, rsrcLength, dataLength);
  9440. X    start_data();
  9441. X    }
  9442. X    if(verbose) {
  9443. X    (void)fprintf(stderr, "\tData: ");
  9444. X    }
  9445. X    jdw_wrfork(dataLength);
  9446. X    if(write_it) {
  9447. X    start_rsrc();
  9448. X    }
  9449. X    if(verbose) {
  9450. X    (void)fprintf(stderr, ", Rsrc: ");
  9451. X    }
  9452. X    jdw_wrfork(rsrcLength);
  9453. X    if(write_it) {
  9454. X    end_file();
  9455. X    }
  9456. X    if(verbose) {
  9457. X    (void)fprintf(stderr, ".\n");
  9458. X    }
  9459. X}
  9460. X
  9461. Xstatic void jdw_wrfork(length)
  9462. Xunsigned long length;
  9463. X{
  9464. X    int olength, ilength, i;
  9465. X    unsigned long origlength, comprlength;
  9466. X
  9467. X    if(length == 0) {
  9468. X    (void)fprintf(stderr, "empty");
  9469. X    return;
  9470. X    }
  9471. X    (void)fprintf(stderr, "Huffman compressed ");
  9472. X    comprlength = 0;
  9473. X    origlength = length;
  9474. X    while(length > 0) {
  9475. X    olength = getb(infp) & BYTEMASK;
  9476. X    olength = (olength << 8) | (getb(infp) & BYTEMASK);
  9477. X    ilength = getb(infp) & BYTEMASK;
  9478. X    ilength = (ilength << 8) | (getb(infp) & BYTEMASK);
  9479. X    if(write_it) {
  9480. X        jdw_block(olength);
  9481. X    } else {
  9482. X        for(i = 0; i < ilength; i++) {
  9483. X        (void)getb(infp);
  9484. X        }
  9485. X    }
  9486. X    comprlength += ilength + 4;
  9487. X    length -= olength;
  9488. X    }
  9489. X    if(verbose) {
  9490. X    (void)fprintf(stderr, "(%4.1f%%)", 100.0 * comprlength / origlength);
  9491. X    }
  9492. X}
  9493. X
  9494. Xstatic void jdw_block(olength)
  9495. Xint olength;
  9496. X{
  9497. X    bytesread = 0;
  9498. X    read_tree();
  9499. X    /* Put reading back at a word boundary! */
  9500. X    while(bytesread & 3) {
  9501. X    (void)getb(infp);
  9502. X    bytesread++;
  9503. X    }
  9504. X    clrhuff();
  9505. X    de_huffman((unsigned long)olength);
  9506. X}
  9507. X#else /* JDW */
  9508. Xint jdw; /* keep lint and some compilers happy */
  9509. X#endif /* JDW */
  9510. X
  9511. SHAR_EOF
  9512. if test 3552 -ne "`wc -c < 'jdw.c'`"
  9513. then
  9514.     echo shar: "error transmitting 'jdw.c'" '(should have been 3552 characters)'
  9515. fi
  9516. fi
  9517. echo shar: "extracting 'jdw.h'" '(446 characters)'
  9518. if test -f 'jdw.h'
  9519. then
  9520.     echo shar: "will not over-write existing file 'jdw.h'"
  9521. else
  9522. sed 's/^X//' << \SHAR_EOF > 'jdw.h'
  9523. X#define    J_MAGIC        0
  9524. X#define J_TYPE        6
  9525. X#define J_AUTH        10
  9526. X#define    J_FINFO        14
  9527. X#define    J_DATALENGTH    22
  9528. X#define J_RSRCLENGTH    26
  9529. X#define    J_CTIME        30
  9530. X#define    J_MTIME        34
  9531. X#define    J_FLENGTH    38
  9532. X
  9533. Xtypedef struct fileHdr {
  9534. X    char        magic[6];
  9535. X    unsigned long    type;
  9536. X    unsigned long    auth;
  9537. X    char        finfo[8];
  9538. X    unsigned long    dataLength;
  9539. X    unsigned long    rsrcLength;
  9540. X    unsigned long    ctime;
  9541. X    unsigned long    mtime;
  9542. X    char        flength;
  9543. X    char        fname[32];    /* actually flength */
  9544. X};
  9545. X
  9546. SHAR_EOF
  9547. if test 446 -ne "`wc -c < 'jdw.h'`"
  9548. then
  9549.     echo shar: "error transmitting 'jdw.h'" '(should have been 446 characters)'
  9550. fi
  9551. fi
  9552. echo shar: "extracting 'de_lzh.c'" '(6147 characters)'
  9553. if test -f 'de_lzh.c'
  9554. then
  9555.     echo shar: "will not over-write existing file 'de_lzh.c'"
  9556. else
  9557. sed 's/^X//' << \SHAR_EOF > 'de_lzh.c'
  9558. X#include "macunpack.h"
  9559. X#ifdef ZMA
  9560. X#define DELZH
  9561. X#endif /* ZMA */
  9562. X#ifdef LZH
  9563. X#define DELZH
  9564. X#endif /* LZH */
  9565. X#ifdef DELZH
  9566. X#include "globals.h"
  9567. X#include "../util/masks.h"
  9568. X#include "../fileio/wrfile.h"
  9569. X#include "bits_be.h"
  9570. X
  9571. X/* This code is valid for bitsused upto 15. */
  9572. X#define DICBIT    13    /* 12(-lh4-) or 13(-lh5-) */
  9573. X#define UCHAR_MAX    255
  9574. X#define THRESHOLD    3
  9575. X
  9576. Xstatic int decoded;
  9577. Xstatic int bitsused;
  9578. Xstatic unsigned int blocksize;
  9579. Xstatic unsigned int decode_c();
  9580. Xstatic unsigned int decode_p();
  9581. Xstatic void make_table();
  9582. X
  9583. X/* lzh compression */
  9584. Xvoid de_lzh(ibytes, obytes, data, bits)
  9585. Xlong ibytes;
  9586. Xlong obytes;
  9587. Xchar **data;
  9588. Xint bits;
  9589. X{
  9590. X    unsigned int i, r, c;
  9591. X    int remains;
  9592. X
  9593. X    bit_be_inbytes = ibytes;
  9594. X    bit_be_filestart = *data;
  9595. X    bitsused = bits;
  9596. X    bit_be_init_getbits();
  9597. X    blocksize = 0;
  9598. X    decoded = 0;
  9599. X    r = 0;
  9600. X    for(;;) {
  9601. X    c = decode_c();
  9602. X    if(decoded) {
  9603. X        *data = bit_be_filestart;
  9604. X        return;
  9605. X    }
  9606. X    if(c <= UCHAR_MAX) {
  9607. X        out_ptr[r++] = c;
  9608. X        obytes--;
  9609. X        if(obytes == 0) {
  9610. X        *data = bit_be_filestart;
  9611. X        return;
  9612. X        }
  9613. X    } else {
  9614. X        remains = c - (UCHAR_MAX + 1 - THRESHOLD);
  9615. X        i = (r - decode_p() - 1);
  9616. X        while(--remains >= 0) {
  9617. X        out_ptr[r++] = out_ptr[i++];
  9618. X        obytes--;
  9619. X        if(obytes == 0) {
  9620. X            *data = bit_be_filestart;
  9621. X            return;
  9622. X        }
  9623. X        }
  9624. X    }
  9625. X    }
  9626. X}
  9627. X
  9628. X#define MAXMATCH 256
  9629. X#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
  9630. X#define CBIT 9
  9631. X#define CODE_BIT 16
  9632. X#define NP (DICBIT + 1)
  9633. X#define NT (CODE_BIT + 3)
  9634. X#define PBIT 4  /* smallest integer such that (1U << PBIT) > NP */
  9635. X#define TBIT 5  /* smallest integer such that (1U << TBIT) > NT */
  9636. X#if NT > NP
  9637. X# define NPT NT
  9638. X#else
  9639. X# define NPT NP
  9640. X#endif
  9641. X
  9642. Xstatic unsigned int left[2 * NC - 1], right[2 * NC - 1];
  9643. Xstatic unsigned char c_len[NC], pt_len[NPT];
  9644. Xstatic unsigned int c_table[4096], pt_table[256];
  9645. X
  9646. Xstatic void read_pt_len(nn, nbit, i_special)
  9647. Xint nn;
  9648. Xint nbit;
  9649. Xint i_special;
  9650. X{
  9651. X    int i, c, n;
  9652. X    unsigned int mask;
  9653. X
  9654. X    n = bit_be_getbits(nbit);
  9655. X    if (n == 0) {
  9656. X    c = bit_be_getbits(nbit);
  9657. X    for (i = 0; i < nn; i++) {
  9658. X        pt_len[i] = 0;
  9659. X    }
  9660. X    for (i = 0; i < 256; i++) {
  9661. X        pt_table[i] = c;
  9662. X    }
  9663. X    } else {
  9664. X    i = 0;
  9665. X    while (i < n) {
  9666. X        c = bit_be_bitbuf >> (BITBUFSIZ - 3);
  9667. X        if (c == 7) {
  9668. X        mask = (unsigned) 1 << (BITBUFSIZ - 1 - 3);
  9669. X        while (mask & bit_be_bitbuf) {
  9670. X            mask >>= 1;
  9671. X            c++;
  9672. X        }
  9673. X        }
  9674. X        bit_be_fillbuf((c < 7) ? 3 : c - 3);
  9675. X        pt_len[i++] = c;
  9676. X        if (i == i_special) {
  9677. X        c = bit_be_getbits(2);
  9678. X        while (--c >= 0) {
  9679. X            pt_len[i++] = 0;
  9680. X        }
  9681. X        }
  9682. X    }
  9683. X    while (i < nn) {
  9684. X        pt_len[i++] = 0;
  9685. X    }
  9686. X    make_table(nn, pt_len, 8, pt_table);
  9687. X    }
  9688. X}
  9689. X
  9690. Xstatic void read_c_len()
  9691. X{
  9692. X    int i, c, n;
  9693. X    unsigned int mask;
  9694. X
  9695. X    n = bit_be_getbits(CBIT);
  9696. X    if (n == 0) {
  9697. X    c = bit_be_getbits(CBIT);
  9698. X    for (i = 0; i < NC; i++) {
  9699. X        c_len[i] = 0;
  9700. X    }
  9701. X    for (i = 0; i < 4096; i++) {
  9702. X        c_table[i] = c;
  9703. X    }
  9704. X    } else {
  9705. X    i = 0;
  9706. X    while (i < n) {
  9707. X        c = pt_table[bit_be_bitbuf >> (BITBUFSIZ - 8)];
  9708. X        if (c >= NT) {
  9709. X        mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
  9710. X        do {
  9711. X            if (bit_be_bitbuf & mask) {
  9712. X            c = right[c];
  9713. X            } else {
  9714. X            c = left [c];
  9715. X            }
  9716. X            mask >>= 1;
  9717. X        } while (c >= NT);
  9718. X        }
  9719. X        bit_be_fillbuf((int)pt_len[c]);
  9720. X        if (c <= 2) {
  9721. X        if (c == 0) {
  9722. X            c = 1;
  9723. X        } else if (c == 1) {
  9724. X            c = bit_be_getbits(4) + 3;
  9725. X        } else {
  9726. X            c = bit_be_getbits(CBIT) + 20;
  9727. X        }
  9728. X        while (--c >= 0) {
  9729. X            c_len[i++] = 0;
  9730. X        }
  9731. X        } else {
  9732. X        c_len[i++] = c - 2;
  9733. X        }
  9734. X    }
  9735. X    while (i < NC) {
  9736. X        c_len[i++] = 0;
  9737. X    }
  9738. X    make_table(NC, c_len, 12, c_table);
  9739. X    }
  9740. X}
  9741. X
  9742. Xstatic unsigned int decode_c()
  9743. X{
  9744. X    unsigned int j, mask;
  9745. X
  9746. X    if (blocksize == 0) {
  9747. X    blocksize = bit_be_getbits(16);
  9748. X    if (blocksize == 0) {
  9749. X        decoded = 1;
  9750. X        return 0;
  9751. X    }
  9752. X    read_pt_len(NT, TBIT, 3);
  9753. X    read_c_len();
  9754. X    read_pt_len(bitsused + 1, PBIT, -1);
  9755. X    }
  9756. X    blocksize--;
  9757. X    j = c_table[bit_be_bitbuf >> (BITBUFSIZ - 12)];
  9758. X    if (j >= NC) {
  9759. X    mask = (unsigned) 1 << (BITBUFSIZ - 1 - 12);
  9760. X    do {
  9761. X        if (bit_be_bitbuf & mask) {
  9762. X        j = right[j];
  9763. X        } else {
  9764. X        j = left [j];
  9765. X        }
  9766. X        mask >>= 1;
  9767. X    } while (j >= NC);
  9768. X    }
  9769. X    bit_be_fillbuf((int)c_len[j]);
  9770. X    return j;
  9771. X}
  9772. X
  9773. Xstatic unsigned int decode_p()
  9774. X{
  9775. X    unsigned int j, mask;
  9776. X
  9777. X    j = pt_table[bit_be_bitbuf >> (BITBUFSIZ - 8)];
  9778. X    if (j > bitsused) {
  9779. X    mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
  9780. X    do {
  9781. X        if (bit_be_bitbuf & mask) {
  9782. X        j = right[j];
  9783. X        } else {
  9784. X        j = left [j];
  9785. X        }
  9786. X        mask >>= 1;
  9787. X    } while (j > bitsused);
  9788. X    }
  9789. X    bit_be_fillbuf((int)pt_len[j]);
  9790. X    if (j != 0) {
  9791. X    j = ((unsigned) 1 << (j - 1)) + bit_be_getbits((int) (j - 1));
  9792. X    }
  9793. X    return j;
  9794. X}
  9795. X
  9796. Xstatic void make_table(nchar, bitlen, tablebits, table)
  9797. Xint nchar;
  9798. Xunsigned char bitlen[];
  9799. Xint tablebits;
  9800. Xunsigned int table[];
  9801. X{
  9802. X    unsigned int count[17], weight[17], start[18], *p;
  9803. X    unsigned int i, k, len, ch, jutbits, avail, nextcode, mask;
  9804. X
  9805. X    for (i = 1; i <= 16; i++) {
  9806. X    count[i] = 0;
  9807. X    }
  9808. X    for (i = 0; i < nchar; i++) {
  9809. X    count[bitlen[i]]++;
  9810. X    }
  9811. X
  9812. X    start[1] = 0;
  9813. X    for (i = 1; i <= 16; i++) {
  9814. X    start[i + 1] = start[i] + (count[i] << (16 - i));
  9815. X    }
  9816. X
  9817. X    jutbits = 16 - tablebits;
  9818. X    for (i = 1; i <= tablebits; i++) {
  9819. X    start[i] >>= jutbits;
  9820. X    weight[i] = (unsigned) 1 << (tablebits - i);
  9821. X    }
  9822. X    while (i <= 16) {
  9823. X       weight[i] = (unsigned) 1 << (16 - i);
  9824. X       i++;
  9825. X    }
  9826. X
  9827. X    i = start[tablebits + 1] >> jutbits;
  9828. X    if (i != (unsigned int)((unsigned) 1 << 16)) {
  9829. X    k = 1 << tablebits;
  9830. X    while (i != k) {
  9831. X        table[i++] = 0;
  9832. X    }
  9833. X    }
  9834. X
  9835. X    avail = nchar;
  9836. X    mask = (unsigned) 1 << (15 - tablebits);
  9837. X    for (ch = 0; ch < nchar; ch++) {
  9838. X    if ((len = bitlen[ch]) == 0) {
  9839. X        continue;
  9840. X    }
  9841. X    nextcode = start[len] + weight[len];
  9842. X    if (len <= tablebits) {
  9843. X        for (i = start[len]; i < nextcode; i++) {
  9844. X        table[i] = ch;
  9845. X        }
  9846. X    } else {
  9847. X        k = start[len];
  9848. X        p = &table[k >> jutbits];
  9849. X        i = len - tablebits;
  9850. X        while (i != 0) {
  9851. X        if (*p == 0) {
  9852. X            right[avail] = left[avail] = 0;
  9853. X            *p = avail++;
  9854. X        }
  9855. X        if (k & mask) {
  9856. X            p = &right[*p];
  9857. X        } else {
  9858. X            p = &left[*p];
  9859. X        }
  9860. X        k <<= 1;
  9861. X        i--;
  9862. X        }
  9863. X        *p = ch;
  9864. X    }
  9865. X    start[len] = nextcode;
  9866. X    }
  9867. X}
  9868. X#else /* DELZH */
  9869. Xint delzh; /* keep lint and some compilers happy */
  9870. X#endif /* DELZH */
  9871. X
  9872. SHAR_EOF
  9873. if test 6147 -ne "`wc -c < 'de_lzh.c'`"
  9874. then
  9875.     echo shar: "error transmitting 'de_lzh.c'" '(should have been 6147 characters)'
  9876. fi
  9877. fi
  9878. echo shar: "extracting 'dd.h'" '(3113 characters)'
  9879. if test -f 'dd.h'
  9880. then
  9881.     echo shar: "will not over-write existing file 'dd.h'"
  9882. else
  9883. sed 's/^X//' << \SHAR_EOF > 'dd.h'
  9884. X#define    MAGIC1        "DDAR"
  9885. X#define    MAGIC2        "\253\315\000\124"
  9886. X
  9887. X/* Initial header */
  9888. X#define ARCHHDRCRC     76
  9889. X#define ARCHHDRSIZE     78
  9890. X
  9891. X/* File headers */
  9892. X#define D_MAGIC          0
  9893. X#define D_FILL1          4
  9894. X#define D_FNAME          8
  9895. X#define D_ISDIR         72
  9896. X#define D_ENDDIR     73
  9897. X#define D_DATALENGTH     74
  9898. X#define D_RSRCLENGTH     78
  9899. X#define D_CTIME         82
  9900. X#define D_MTIME         86
  9901. X#define D_FTYPE         90
  9902. X#define D_CREATOR     94
  9903. X#define D_FNDRFLAGS     98
  9904. X#define D_FILL2        100
  9905. X#define D_DATACRC    118
  9906. X#define D_RSRCCRC    120
  9907. X#define D_HDRCRC    122
  9908. X#define FILEHDRSIZE    124
  9909. X
  9910. X/* Compressed file header */
  9911. X#define    C_MAGIC         0
  9912. X#define    C_DATALENGTH     4
  9913. X#define    C_DATACLENGTH     8
  9914. X#define    C_RSRCLENGTH    12
  9915. X#define    C_RSRCCLENGTH    16
  9916. X#define    C_DATAMETHOD    20
  9917. X#define    C_RSRCMETHOD    21
  9918. X#define    C_INFO1        22
  9919. X#define    C_MTIME        24
  9920. X#define    C_CTIME        28
  9921. X#define    C_FTYPE        32
  9922. X#define    C_CREATOR    36
  9923. X#define    C_FNDRFLAGS    40
  9924. X#define    C_FILL1        42
  9925. X#define    C_DATACRC    48
  9926. X#define    C_RSRCCRC    50
  9927. X#define    C_INFO2        52
  9928. X#define    C_DATAINFO    54
  9929. X#define    C_RSRCINFO    56
  9930. X#define    C_FILL2        58
  9931. X#define C_DATACRC2    78
  9932. X#define C_RSRCCRC2    80
  9933. X#define    C_HDRCRC    82
  9934. X#define    CFILEHDRSIZE    84
  9935. X
  9936. Xtypedef long OSType;
  9937. X
  9938. Xtypedef struct fileHdr {        /* 124 bytes */
  9939. X    unsigned char    magic[4];    /* "DDAR" */
  9940. X    unsigned char    fill1[4];    /* ??? */
  9941. X    unsigned char    fName[64];    /* a STR63 */
  9942. X    unsigned char    isdir;        /* starts a directory? */
  9943. X    unsigned char    enddir;        /* terminates a directory? */
  9944. X    unsigned long    dataLength;    /* lengths */
  9945. X    unsigned long    rsrcLength;
  9946. X    unsigned long    creationDate;
  9947. X    unsigned long    modDate;
  9948. X    OSType    fType;            /* file type */
  9949. X    OSType    fCreator;        /* er... */
  9950. X    unsigned short FndrFlags;    /* copy of Finder flags.  For our
  9951. X                        purposes, we can clear:
  9952. X                        busy,onDesk */
  9953. X    unsigned char    fill2[18];    /* ??? */
  9954. X    unsigned short    datacrc;    /* checksum */
  9955. X    unsigned short    rsrccrc;
  9956. X    unsigned short    hdrcrc;        /* true crc */
  9957. X};
  9958. X
  9959. Xtypedef struct fileCHdr {        /* 84 bytes */
  9960. X    unsigned char    magic[4];    /* "\253\315\000\124" */
  9961. X    unsigned long    dataLength;    /* lengths */
  9962. X    unsigned long    dataCLength;
  9963. X    unsigned long    rsrcLength;
  9964. X    unsigned long    rsrcCLength;
  9965. X    unsigned char    datamethod;    /* compression method used */
  9966. X    unsigned char    rsrcmethod;
  9967. X    unsigned char    info1;        /* flags ??? */
  9968. X    unsigned char    fill3;
  9969. X    unsigned long    modDate;
  9970. X    unsigned long    creationDate;
  9971. X    OSType    fType;            /* file type */
  9972. X    OSType    fCreator;        /* er... */
  9973. X    unsigned short FndrFlags;    /* copy of Finder flags.  For our
  9974. X                        purposes, we can clear:
  9975. X                        busy,onDesk */
  9976. X    unsigned char    fill1[6];    /* ??? */
  9977. X    unsigned short    datacrc;    /* checksum */
  9978. X    unsigned short    rsrccrc;
  9979. X    unsigned char    info2;        /* flags ??? */
  9980. X    unsigned char    fill4;
  9981. X    unsigned short    datainfo;    /* ??? */
  9982. X    unsigned short    rsrcinfo;    /* ??? */
  9983. X    unsigned char    fill2[20];    /* ??? */
  9984. X    unsigned short    datacrc2;    /* other checksum */
  9985. X    unsigned short    rsrccrc2;
  9986. X    unsigned short    hdrcrc;        /* true crc */
  9987. X};
  9988. X
  9989. X#define    DD_FILE    0
  9990. X#define    DD_COPY    1
  9991. X#define    DD_SDIR    2
  9992. X#define    DD_EDIR    3
  9993. X#define    DD_IVAL    4
  9994. X
  9995. X/* Methods used */
  9996. X#define    nocomp        0
  9997. X#define lzc        1
  9998. X#define method2        2
  9999. X#define rle        3
  10000. X#define huffman        4
  10001. X#define method5        5
  10002. X#define    method6        6
  10003. X#define lzss        7
  10004. X#define    cpt_compat    8
  10005. X#define    method9        9
  10006. X
  10007. X#define    ESC        0x144    /* Repeat packing escape */
  10008. X
  10009. SHAR_EOF
  10010. if test 3113 -ne "`wc -c < 'dd.h'`"
  10011. then
  10012.     echo shar: "error transmitting 'dd.h'" '(should have been 3113 characters)'
  10013. fi
  10014. fi
  10015. echo shar: "extracting 'dd.c'" '(25074 characters)'
  10016. if test -f 'dd.c'
  10017. then
  10018.     echo shar: "will not over-write existing file 'dd.c'"
  10019. else
  10020. sed 's/^X//' << \SHAR_EOF > 'dd.c'
  10021. X#include "macunpack.h"
  10022. X#ifdef DD
  10023. X#include "globals.h"
  10024. X#include "dd.h"
  10025. X#include "crc.h"
  10026. X#include "../fileio/machdr.h"
  10027. X#include "../fileio/wrfile.h"
  10028. X#include "../fileio/fileglob.h"
  10029. X#include "../util/masks.h"
  10030. X#include "../util/util.h"
  10031. X
  10032. Xextern char *malloc();
  10033. Xextern char *realloc();
  10034. Xextern char *strcpy();
  10035. Xextern char *strncpy();
  10036. Xextern void cpt_wrfile1();
  10037. Xextern void core_compress();
  10038. Xextern void de_compress();
  10039. X
  10040. Xstatic void dd_name();
  10041. Xstatic int dd_filehdr();
  10042. Xstatic void dd_cfilehdr();
  10043. Xstatic int dd_valid();
  10044. Xstatic int dd_valid1();
  10045. Xstatic char *dd_methname();
  10046. Xstatic unsigned long dd_checksum();
  10047. Xstatic void dd_chksum();
  10048. Xstatic unsigned long dd_checkor();
  10049. Xstatic void dd_do_delta();
  10050. Xstatic void dd_delta();
  10051. Xstatic void dd_delta3();
  10052. Xstatic void dd_copy();
  10053. Xstatic void dd_copyfile();
  10054. Xstatic void dd_expand();
  10055. Xstatic void dd_expandfile();
  10056. Xstatic void dd_nocomp();
  10057. Xstatic void dd_lzc();
  10058. X#ifdef UNTESTED
  10059. Xstatic void dd_rle();
  10060. X#ifdef NOTIMPLEMENTED
  10061. Xstatic void dd_huffman();
  10062. X#endif /* NOTIMPLEMENTED */
  10063. Xstatic void dd_lzss();
  10064. Xstatic int dd_getbits();
  10065. X#endif /* UNTESTED */
  10066. Xstatic void dd_cpt_compat();
  10067. X
  10068. Xtypedef struct methodinfo {
  10069. X    char *name;
  10070. X    int number;
  10071. X};
  10072. X
  10073. Xstatic struct methodinfo methods[] = {
  10074. X    {"NoComp",  nocomp},
  10075. X    {"LZC",     lzc},
  10076. X    {"???",    method2},
  10077. X    {"RLE",     rle},
  10078. X    {"Huffman", huffman},
  10079. X    {"???",    method5},
  10080. X    {"???",    method6},
  10081. X    {"LZSS",    lzss},
  10082. X    {"RLE/LZH",    cpt_compat},
  10083. X    {"???",    method9},
  10084. X};
  10085. Xstatic unsigned char *dd_archive;
  10086. Xstatic unsigned char *dd_data_ptr;
  10087. Xstatic int dd_archive_size;
  10088. Xstatic int dd_max_archive_size;
  10089. Xstatic unsigned char *dd_dirst;
  10090. Xstatic int dd_dirstptr;
  10091. Xstatic int dd_dirstmax;
  10092. Xstatic int dd_xor;
  10093. Xstatic long dd_bitbuf;
  10094. Xstatic int dd_bitcount;
  10095. Xstatic unsigned char *dd_bitptr;
  10096. Xstatic char dd_LZbuff[2048];
  10097. X
  10098. Xvoid dd_file(bin_hdr)
  10099. Xunsigned char *bin_hdr;
  10100. X{
  10101. X    unsigned long data_size;
  10102. X    int i;
  10103. X    struct fileCHdr cf;
  10104. X    char ftype[5], fauth[5];
  10105. X
  10106. X    updcrc = binhex_updcrc;
  10107. X    crcinit = binhex_crcinit;
  10108. X    dd_name(bin_hdr);
  10109. X    for(i = 0; i < INFOBYTES; i++) {
  10110. X    info[i] = bin_hdr[i];
  10111. X    }
  10112. X    transname(info + I_NAMEOFF + 1, text, (int)info[I_NAMEOFF] & BYTEMASK);
  10113. X    data_size = get4(info + I_DLENOFF);
  10114. X    if(data_size > dd_max_archive_size) {
  10115. X    if(dd_max_archive_size == 0) {
  10116. X        dd_archive = (unsigned char *)malloc((unsigned)data_size);
  10117. X    } else {
  10118. X        dd_archive = (unsigned char *)realloc((char *)dd_archive,
  10119. X                        (unsigned)data_size);
  10120. X    }
  10121. X    dd_max_archive_size = data_size;
  10122. X    if(dd_archive == NULL) {
  10123. X        (void)fprintf(stderr, "Insufficient memory.\n");
  10124. X        exit(1);
  10125. X    }
  10126. X    }
  10127. X    dd_archive_size = data_size;
  10128. X    if(fread((char *)dd_archive, 1, (int)data_size, infp) != data_size) {
  10129. X    (void)fprintf(stderr, "Premature EOF\n");
  10130. X#ifdef SCAN
  10131. X    do_error("Premature EOF");
  10132. X#endif /* SCAN */
  10133. X    exit(1);
  10134. X    }
  10135. X    dd_data_ptr = dd_archive;
  10136. X    dd_cfilehdr(&cf);
  10137. X    write_it = 1;
  10138. X    if(list) {
  10139. X    do_indent(indent);
  10140. X    transname(info + I_TYPEOFF, ftype, 4);
  10141. X    transname(info + I_AUTHOFF, fauth, 4);
  10142. X    (void)fprintf(stderr,
  10143. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  10144. X        text, ftype, fauth,
  10145. X        (long)get4(info + I_DLENOFF), (long)get4(info + I_RLENOFF));
  10146. X    if(info_only) {
  10147. X        write_it = 0;
  10148. X    }
  10149. X    if(query) {
  10150. X        write_it = do_query();
  10151. X    } else {
  10152. X        (void)fputc('\n', stderr);
  10153. X    }
  10154. X    }
  10155. X    if(!dd_valid((int)cf.datamethod, (int)cf.rsrcmethod)) {
  10156. X    (void)fprintf(stderr, "\tUnimplemented method found: %d %d\n",
  10157. X        cf.datamethod, cf.rsrcmethod);
  10158. X#ifdef SCAN
  10159. X    do_error("macunpack: Unimplemented method found");
  10160. X#endif /* SCAN */
  10161. X    return;
  10162. X    }
  10163. X
  10164. X    if(write_it) {
  10165. X    define_name(text);
  10166. X    }
  10167. X    if(write_it || list) {
  10168. X    dd_expand(cf, dd_data_ptr);
  10169. X    }
  10170. X}
  10171. X
  10172. Xvoid dd_arch(bin_hdr)
  10173. Xunsigned char *bin_hdr;
  10174. X{
  10175. X    unsigned long data_size;
  10176. X    unsigned long crc, filecrc;
  10177. X    struct fileHdr f;
  10178. X    struct fileCHdr cf;
  10179. X    char locname[64];
  10180. X    int i, nlength;
  10181. X
  10182. X    updcrc = binhex_updcrc;
  10183. X    crcinit = binhex_crcinit;
  10184. X    data_size = get4((char *)bin_hdr + I_DLENOFF);
  10185. X    if(data_size > dd_max_archive_size) {
  10186. X    if(dd_max_archive_size == 0) {
  10187. X        dd_archive = (unsigned char *)malloc((unsigned)data_size);
  10188. X    } else {
  10189. X        dd_archive = (unsigned char *)realloc((char *)dd_archive,
  10190. X                        (unsigned)data_size);
  10191. X    }
  10192. X    dd_max_archive_size = data_size;
  10193. X    }
  10194. X    dd_archive_size = data_size;
  10195. X    if(fread((char *)dd_archive, 1, (int)data_size, infp) != data_size) {
  10196. X    (void)fprintf(stderr, "Insufficient memory.\n");
  10197. X    exit(1);
  10198. X    }
  10199. X    dd_name(bin_hdr);
  10200. X    nlength = bin_hdr[I_NAMEOFF];
  10201. X    for(i = 0; i < INFOBYTES; i++) {
  10202. X    info[i] = 0;
  10203. X    }
  10204. X    info[I_NAMEOFF] = nlength;
  10205. X    for(i = 1; i <= nlength; i++) {
  10206. X    info[I_NAMEOFF + i] = bin_hdr[I_NAMEOFF + i];
  10207. X    }
  10208. X    transname(info + I_NAMEOFF + 1, text, nlength);
  10209. X    (void)strcpy(locname, text);
  10210. X    if(list) {
  10211. X    do_indent(indent);
  10212. X    (void)fprintf(stderr, "folder=\"%s\"", text);
  10213. X    if(query) {
  10214. X        if(!do_query()) {
  10215. X        return;
  10216. X        }
  10217. X    } else {
  10218. X        (void)fputc('\n', stderr);
  10219. X    }
  10220. X    indent++;
  10221. X    }
  10222. X    if(!info_only) {
  10223. X    do_mkdir(text, info);
  10224. X    }
  10225. X
  10226. X    if(strncmp((char *)dd_archive, "DDAR", 4)) {
  10227. X    (void)fprintf(stderr, "Magic archive header error\n");
  10228. X#ifdef SCAN
  10229. X    do_error("macunpack: Magic archive header error");
  10230. X#endif /* SCAN */
  10231. X    exit(1);
  10232. X    }
  10233. X    crc = (*updcrc)(crcinit, dd_archive, ARCHHDRSIZE - 2);
  10234. X    filecrc = get2((char *)dd_archive + ARCHHDRCRC);
  10235. X    if(crc != filecrc) {
  10236. X    (void)fprintf(stderr, "Header CRC mismatch: got 0x%02x, need 0x%02x\n",
  10237. X        (int)crc, (int)filecrc);
  10238. X#ifdef SCAN
  10239. X    do_error("macunpack: Header CRC mismatch");
  10240. X#endif /* SCAN */
  10241. X    exit(1);
  10242. X    }
  10243. X    dd_data_ptr = dd_archive + ARCHHDRSIZE;
  10244. X    while(dd_data_ptr < dd_archive + data_size) {
  10245. X    switch(dd_filehdr(&f, &cf, dir_skip)) {
  10246. X    case DD_FILE:
  10247. X        dd_chksum(f, dd_data_ptr);
  10248. X        dd_expand(cf, dd_data_ptr);
  10249. X    case DD_IVAL:
  10250. X        dd_data_ptr += f.dataLength - CFILEHDRSIZE;
  10251. X        break;
  10252. X    case DD_COPY:
  10253. X        dd_copy(f, dd_data_ptr);
  10254. X        dd_data_ptr += f.dataLength + f.rsrcLength;
  10255. X        break;
  10256. X    case DD_SDIR:
  10257. X        if(write_it || info_only) {
  10258. X        if(write_it) {
  10259. X            do_mkdir(text, info);
  10260. X        }
  10261. X        if(dd_dirstptr == dd_dirstmax) {
  10262. X            if(dd_dirstmax == 0) {
  10263. X            dd_dirst = (unsigned char *)malloc(64);
  10264. X            } else {
  10265. X            dd_dirst = (unsigned char *)realloc((char *)dd_dirst,
  10266. X                        (unsigned)dd_dirstmax + 64);
  10267. X            }
  10268. X            dd_dirstmax += 64;
  10269. X        }
  10270. X        for(i = 0; i < 64; i++) {
  10271. X            dd_dirst[dd_dirstptr + i] = text[i];
  10272. X        }
  10273. X        dd_dirst += 64;
  10274. X        indent++;
  10275. X        } else {
  10276. X        dir_skip++;
  10277. X        }
  10278. X        break;
  10279. X    case DD_EDIR:
  10280. X        if(dir_skip) {
  10281. X        dir_skip--;
  10282. X        } else {
  10283. X        dd_dirst -= 64;
  10284. X        indent--;
  10285. X        if(list) {
  10286. X            do_indent(indent);
  10287. X            (void)fprintf(stderr, "leaving folder \"%s\"\n",
  10288. X                dd_dirst + dd_dirstptr);
  10289. X        }
  10290. X        if(!info_only) {
  10291. X            enddir();
  10292. X        }
  10293. X        }
  10294. X    }
  10295. X    }
  10296. X    if(!info_only) {
  10297. X    enddir();
  10298. X    }
  10299. X    if(list) {
  10300. X    indent--;
  10301. X    do_indent(indent);
  10302. X    (void)fprintf(stderr, "leaving folder \"%s\"\n", locname);
  10303. X    }
  10304. X}
  10305. X
  10306. Xstatic void dd_name(bin_hdr)
  10307. Xunsigned char *bin_hdr;
  10308. X{
  10309. X    int nlength;
  10310. X    unsigned char *extptr;
  10311. X
  10312. X    nlength = bin_hdr[I_NAMEOFF] & BYTEMASK;
  10313. X    extptr = bin_hdr + I_NAMEOFF + nlength - 3;
  10314. X    if(!strncmp((char *)extptr, ".sea", 4) ||
  10315. X       !strncmp((char *)extptr, ".Sea", 4) ||
  10316. X       !strncmp((char *)extptr, ".SEA", 4)) {
  10317. X    nlength -= 4;
  10318. X    extptr[0] = 0;
  10319. X    extptr[1] = 0;
  10320. X    extptr[2] = 0;
  10321. X    extptr[3] = 0;
  10322. X    bin_hdr[I_NAMEOFF] = nlength;
  10323. X    return;
  10324. X    }
  10325. X    extptr++;
  10326. X    if(!strncmp((char *)extptr, ".dd", 3)) {
  10327. X    nlength -=3;
  10328. X    extptr[0] = 0;
  10329. X    extptr[1] = 0;
  10330. X    extptr[2] = 0;
  10331. X    bin_hdr[I_NAMEOFF] = nlength;
  10332. X    return;
  10333. X    }
  10334. X    if(nlength < 31) {
  10335. X    nlength++;
  10336. X    }
  10337. X    bin_hdr[I_NAMEOFF + nlength] = 0xA5;
  10338. X    bin_hdr[I_NAMEOFF] = nlength;
  10339. X}
  10340. X
  10341. Xstatic int dd_filehdr(f, cf, skip)
  10342. Xstruct fileHdr *f;
  10343. Xstruct fileCHdr *cf;
  10344. Xint skip;
  10345. X{
  10346. X    register int i;
  10347. X    unsigned long crc;
  10348. X    int n, to_uncompress;
  10349. X    unsigned char *hdr;
  10350. X    char ftype[5], fauth[5];
  10351. X    unsigned long datalength, rsrclength;
  10352. X
  10353. X    to_uncompress = DD_COPY;
  10354. X    hdr = dd_data_ptr;
  10355. X    dd_data_ptr += FILEHDRSIZE;
  10356. X    for(i = 0; i < INFOBYTES; i++) {
  10357. X    info[i] = '\0';
  10358. X    }
  10359. X    crc = INIT_CRC;
  10360. X    crc = (*updcrc)(crc, hdr, FILEHDRSIZE - 2);
  10361. X
  10362. X    f->hdrcrc = get2((char *)hdr + D_HDRCRC);
  10363. X    if(f->hdrcrc != crc) {
  10364. X    (void)fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n",
  10365. X        f->hdrcrc & WORDMASK, (int)crc);
  10366. X#ifdef SCAN
  10367. X    do_error("macunpack: Header CRC mismatch");
  10368. X#endif /* SCAN */
  10369. X    exit(1);
  10370. X    }
  10371. X
  10372. X    n = hdr[D_FNAME] & BYTEMASK;
  10373. X    if(n > F_NAMELEN) {
  10374. X    n = F_NAMELEN;
  10375. X    }
  10376. X    info[I_NAMEOFF] = n;
  10377. X    copy(info + I_NAMEOFF + 1, (char *)hdr + D_FNAME + 1, n);
  10378. X    transname((char *)hdr + D_FNAME + 1, text, n);
  10379. X
  10380. X    if(!hdr[D_ISDIR]) {
  10381. X    f->datacrc = get2((char *)hdr + D_DATACRC);
  10382. X    f->rsrccrc = get2((char *)hdr + D_RSRCCRC);
  10383. X    f->dataLength = get4((char *)hdr + D_DATALENGTH);
  10384. X    f->rsrcLength = get4((char *)hdr + D_RSRCLENGTH);
  10385. X    copy(info + I_DLENOFF, (char *)hdr + D_DATALENGTH, 4);
  10386. X    copy(info + I_RLENOFF, (char *)hdr + D_RSRCLENGTH, 4);
  10387. X    copy(info + I_CTIMOFF, (char *)hdr + D_CTIME, 4);
  10388. X    copy(info + I_MTIMOFF, (char *)hdr + D_MTIME, 4);
  10389. X    copy(info + I_TYPEOFF, (char *)hdr + D_FTYPE, 4);
  10390. X    copy(info + I_AUTHOFF, (char *)hdr + D_CREATOR, 4);
  10391. X    copy(info + I_FLAGOFF, (char *)hdr + D_FNDRFLAGS, 2);
  10392. X    }
  10393. X
  10394. X    if(hdr[D_ISDIR]) {
  10395. X    to_uncompress = DD_SDIR;
  10396. X    } else if(hdr[D_ENDDIR]) {
  10397. X    to_uncompress = DD_EDIR;
  10398. X    } else if(!no_dd && ((hdr[D_FNDRFLAGS] & 0x80) == 0)) {
  10399. X    dd_cfilehdr(cf);
  10400. X    to_uncompress = DD_FILE;
  10401. X    datalength = cf->dataLength;
  10402. X    rsrclength = cf->rsrcLength;
  10403. X    } else {
  10404. X    datalength = f->dataLength;
  10405. X    rsrclength = f->rsrcLength;
  10406. X    }
  10407. X    hdr[D_FNDRFLAGS] &= 0x7f;
  10408. X    write_it = !skip;
  10409. X    if(list && !skip) {
  10410. X    if(to_uncompress != DD_EDIR) {
  10411. X        do_indent(indent);
  10412. X    }
  10413. X    if(to_uncompress == DD_SDIR) {
  10414. X        (void)fprintf(stderr, "folder=\"%s\"", text);
  10415. X    } else if(to_uncompress != DD_EDIR) {
  10416. X        transname(info + I_TYPEOFF, ftype, 4);
  10417. X        transname(info + I_AUTHOFF, fauth, 4);
  10418. X        (void)fprintf(stderr,
  10419. X            "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  10420. X            text, ftype, fauth, (long)datalength, (long)rsrclength);
  10421. X    }
  10422. X    if(info_only) {
  10423. X        write_it = 0;
  10424. X    }
  10425. X    if(to_uncompress != DD_EDIR) {
  10426. X        if(query) {
  10427. X        write_it = do_query();
  10428. X        } else {
  10429. X        (void)fputc('\n', stderr);
  10430. X        }
  10431. X    }
  10432. X    if(to_uncompress == DD_FILE) {
  10433. X        if(!dd_valid((int)cf->datamethod, (int)cf->rsrcmethod)) {
  10434. X        (void)fprintf(stderr, "\tUnimplemented method found: %d %d\n",
  10435. X            cf->datamethod, cf->rsrcmethod);
  10436. X#ifdef SCAN
  10437. X        do_error("macunpack: Unimplemented method found");
  10438. X#endif /* SCAN */
  10439. X        return DD_IVAL;
  10440. X        }
  10441. X    }
  10442. X    }
  10443. X
  10444. X    if(write_it) {
  10445. X    define_name(text);
  10446. X    }
  10447. X    return to_uncompress;
  10448. X}
  10449. X
  10450. Xstatic void dd_cfilehdr(f)
  10451. Xstruct fileCHdr *f;
  10452. X{
  10453. X    unsigned long crc;
  10454. X    unsigned char *hdr;
  10455. X
  10456. X    hdr = dd_data_ptr;
  10457. X    dd_data_ptr += CFILEHDRSIZE;
  10458. X    crc = INIT_CRC;
  10459. X    crc = (*updcrc)(crc, hdr, CFILEHDRSIZE - 2);
  10460. X
  10461. X    f->hdrcrc = get2((char *)hdr + C_HDRCRC);
  10462. X    if(f->hdrcrc != crc) {
  10463. X    (void)fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n",
  10464. X        f->hdrcrc & WORDMASK, (int)crc);
  10465. X#ifdef SCAN
  10466. X    do_error("macunpack: Header CRC mismatch");
  10467. X#endif /* SCAN */
  10468. X    exit(1);
  10469. X    }
  10470. X
  10471. X    f->dataLength = get4((char *)hdr + C_DATALENGTH);
  10472. X    f->dataCLength = get4((char *)hdr + C_DATACLENGTH);
  10473. X    f->rsrcLength = get4((char *)hdr + C_RSRCLENGTH);
  10474. X    f->rsrcCLength = get4((char *)hdr + C_RSRCCLENGTH);
  10475. X    f->datamethod = hdr[C_DATAMETHOD];
  10476. X    f->rsrcmethod = hdr[C_RSRCMETHOD];
  10477. X    f->datacrc = get2((char *)hdr + C_DATACRC);
  10478. X    f->rsrccrc = get2((char *)hdr + C_RSRCCRC);
  10479. X    f->datainfo = get2((char *)hdr + C_DATAINFO);
  10480. X    f->rsrcinfo = get2((char *)hdr + C_RSRCINFO);
  10481. X    f->datacrc2 = get2((char *)hdr + C_DATACRC2);
  10482. X    f->rsrccrc2 = get2((char *)hdr + C_RSRCCRC2);
  10483. X    f->info1 = hdr[C_INFO1];
  10484. X    f->info2 = hdr[C_INFO2];
  10485. X    copy(info + I_DLENOFF, (char *)hdr + C_DATALENGTH, 4);
  10486. X    copy(info + I_RLENOFF, (char *)hdr + C_RSRCLENGTH, 4);
  10487. X    copy(info + I_CTIMOFF, (char *)hdr + C_CTIME, 4);
  10488. X    copy(info + I_MTIMOFF, (char *)hdr + C_MTIME, 4);
  10489. X    copy(info + I_TYPEOFF, (char *)hdr + C_FTYPE, 4);
  10490. X    copy(info + I_AUTHOFF, (char *)hdr + C_CREATOR, 4);
  10491. X    copy(info + I_FLAGOFF, (char *)hdr + C_FNDRFLAGS, 2);
  10492. X    if(f->info1 >= 0x2a && (f->info2 & 0x80) == 0) {
  10493. X    dd_xor = 0x5a;
  10494. X    } else {
  10495. X    dd_xor = 0;
  10496. X    }
  10497. X}
  10498. X
  10499. Xstatic int dd_valid(dmethod, rmethod)
  10500. Xint dmethod, rmethod;
  10501. X{
  10502. X    return dd_valid1(dmethod) | dd_valid1(rmethod);
  10503. X}
  10504. X
  10505. Xstatic int dd_valid1(method)
  10506. Xint method;
  10507. X{
  10508. X    switch(method) {
  10509. X    case nocomp:
  10510. X    case lzc:
  10511. X#ifdef UNTESTED
  10512. X    case rle:
  10513. X#ifdef NOTIMPLEMENTED
  10514. X    case huffman:
  10515. X#endif /* NOTIMPLEMENTED */
  10516. X    case lzss:
  10517. X#endif /* UNTESTED */
  10518. X    case cpt_compat:
  10519. X    return 1;
  10520. X    }
  10521. X    return 0;
  10522. X}
  10523. X
  10524. Xstatic char *dd_methname(n)
  10525. Xint n;
  10526. X{
  10527. Xint i, nmeths;
  10528. X    nmeths = sizeof(methods) / sizeof(struct methodinfo);
  10529. X    for(i = 0; i < nmeths; i++) {
  10530. X    if(methods[i].number == n) {
  10531. X        return methods[i].name;
  10532. X    }
  10533. X    }
  10534. X    return NULL;
  10535. X}
  10536. X
  10537. Xstatic unsigned long dd_checksum(init, buffer, length)
  10538. Xunsigned long init;
  10539. Xchar *buffer;
  10540. Xunsigned long length;
  10541. X{
  10542. X    int i;
  10543. X    unsigned long cks;
  10544. X
  10545. X    cks = init;
  10546. X    for(i = 0; i < length; i++) {
  10547. X    cks += *buffer++ & BYTEMASK;
  10548. X    }
  10549. X    return cks & WORDMASK;
  10550. X}
  10551. X
  10552. Xstatic void dd_chksum(hdr, data)
  10553. Xstruct fileHdr hdr;
  10554. Xunsigned char *data;
  10555. X{
  10556. X    unsigned long cks;
  10557. X
  10558. X    if(write_it) {
  10559. X    cks = dd_checksum(INIT_CRC, (char *)data - CFILEHDRSIZE,
  10560. X              hdr.dataLength);
  10561. X    if(hdr.datacrc != cks) {
  10562. X        (void)fprintf(stderr,
  10563. X        "Checksum error on compressed file: need 0x%04x, got 0x%04x\n",
  10564. X        hdr.datacrc, (int)cks);
  10565. X#ifdef SCAN
  10566. X        do_error("macunpack: Checksum error on compressed file");
  10567. X#endif /* SCAN */
  10568. X        exit(1);
  10569. X    }
  10570. X    }
  10571. X}
  10572. X
  10573. Xstatic unsigned long dd_checkor(init, buffer, length)
  10574. Xunsigned long init;
  10575. Xchar *buffer;
  10576. Xunsigned long length;
  10577. X{
  10578. X    int i;
  10579. X    unsigned long cks;
  10580. X
  10581. X    cks = init;
  10582. X    for(i = 0; i < length; i++) {
  10583. X    cks ^= *buffer++ & BYTEMASK;
  10584. X    }
  10585. X    return cks & WORDMASK;
  10586. X}
  10587. X
  10588. Xstatic void dd_do_delta(out_ptr, nbytes, kind)
  10589. Xchar *out_ptr;
  10590. Xunsigned long nbytes;
  10591. Xint kind;
  10592. X{
  10593. X    switch(kind) {
  10594. X    case 0:
  10595. X    break;
  10596. X    case 1:
  10597. X    dd_delta(out_ptr, nbytes);
  10598. X    break;
  10599. X    case 2:
  10600. X    dd_delta3(out_ptr, nbytes);
  10601. X    break;
  10602. X    default:
  10603. X    (void)fprintf(stderr, "Illegal kind value found: %d\n", kind);
  10604. X#ifdef SCAN
  10605. X    do_error("Illegal kind value found");
  10606. X#endif /* SCAN */
  10607. X    exit(1);
  10608. X    }
  10609. X}
  10610. X
  10611. Xstatic void dd_delta(out_ptr, nbytes)
  10612. Xchar *out_ptr;
  10613. Xunsigned long nbytes;
  10614. X{
  10615. X    int i, sum = 0;
  10616. X
  10617. X    for(i = 0; i < nbytes; i++) {
  10618. X    sum = (sum + *out_ptr) & BYTEMASK;
  10619. X    *out_ptr++ = sum;
  10620. X    }
  10621. X}
  10622. X
  10623. Xstatic void dd_delta3(out_ptr, nbytes)
  10624. Xchar *out_ptr;
  10625. Xunsigned long nbytes;
  10626. X{
  10627. X    int i, sum1 = 0, sum2 = 0, sum3 = 0;
  10628. X
  10629. X    for(i = 0; i < nbytes; i += 3) {
  10630. X    sum1 = (sum1 + *out_ptr) & BYTEMASK;
  10631. X    *out_ptr++ = sum1;
  10632. X    if(i < nbytes - 1) {
  10633. X        sum2 = (sum2 + *out_ptr) & BYTEMASK;
  10634. X        *out_ptr++ = sum2;
  10635. X        if(i < nbytes) {
  10636. X        sum3 = (sum3 + *out_ptr) & BYTEMASK;
  10637. X        *out_ptr++ = sum3;
  10638. X        }
  10639. X    }
  10640. X    }
  10641. X}
  10642. X
  10643. X/*---------------------------------------------------------------------------*/
  10644. X/*    Archive only, no compression                         */
  10645. X/*---------------------------------------------------------------------------*/
  10646. Xstatic void dd_copy(hdr, data)
  10647. Xstruct fileHdr hdr;
  10648. Xunsigned char *data;
  10649. X{
  10650. X    unsigned long cks;
  10651. X
  10652. X    if(write_it) {
  10653. X    start_info(info, hdr.rsrcLength, hdr.dataLength);
  10654. X    }
  10655. X    if(verbose) {
  10656. X    (void)fprintf(stderr, "\tNo compression");
  10657. X    }
  10658. X    if(write_it) {
  10659. X    start_data();
  10660. X    }
  10661. X    dd_copyfile(hdr.dataLength, data);
  10662. X    data += hdr.dataLength;
  10663. X    if(write_it) {
  10664. X    cks = dd_checksum(INIT_CRC, out_buffer, hdr.dataLength);
  10665. X    if(hdr.datacrc != cks) {
  10666. X        (void)fprintf(stderr,
  10667. X        "Checksum error on data fork: need 0x%04x, got 0x%04x\n",
  10668. X        hdr.datacrc, (int)cks);
  10669. X#ifdef SCAN
  10670. X        do_error("macunpack: Checksum error on data fork");
  10671. X#endif /* SCAN */
  10672. X        exit(1);
  10673. X    }
  10674. X    }
  10675. X    if(write_it) {
  10676. X    start_rsrc();
  10677. X    }
  10678. X    dd_copyfile(hdr.rsrcLength, data);
  10679. X    data += hdr.rsrcLength;
  10680. X    if(write_it) {
  10681. X    cks = dd_checksum(INIT_CRC, out_buffer, hdr.rsrcLength);
  10682. X    if(hdr.rsrccrc != cks) {
  10683. X        (void)fprintf(stderr,
  10684. X        "Checksum error on resource fork: need 0x%04x, got 0x%04x\n",
  10685. X        hdr.rsrccrc, (int)cks);
  10686. X#ifdef SCAN
  10687. X        do_error("macunpack: Checksum error on resource fork");
  10688. X#endif /* SCAN */
  10689. X        exit(1);
  10690. X    }
  10691. X    end_file();
  10692. X    }
  10693. X    if(verbose) {
  10694. X    (void)fprintf(stderr, ".\n");
  10695. X    }
  10696. X}
  10697. X
  10698. Xstatic void dd_copyfile(obytes, data)
  10699. Xunsigned long obytes;
  10700. Xunsigned char *data;
  10701. X{
  10702. X    if(obytes == 0) {
  10703. X    return;
  10704. X    }
  10705. X    if(write_it) {
  10706. X    copy(out_ptr, (char *)data, (int)obytes);
  10707. X    }
  10708. X}
  10709. X
  10710. X/*---------------------------------------------------------------------------*/
  10711. X/*    Possible compression, and perhaps in an archive                 */
  10712. X/*---------------------------------------------------------------------------*/
  10713. Xstatic void dd_expand(hdr, data)
  10714. Xstruct fileCHdr hdr;
  10715. Xunsigned char *data;
  10716. X{
  10717. X    unsigned long cks;
  10718. X    char *out_buf;
  10719. X
  10720. X    if(write_it) {
  10721. X    start_info(info, hdr.rsrcLength, hdr.dataLength);
  10722. X    }
  10723. X    if(verbose) {
  10724. X    (void)fprintf(stderr, "\tData: ");
  10725. X    }
  10726. X    if(write_it) {
  10727. X    start_data();
  10728. X    }
  10729. X    out_buf = out_buffer;
  10730. X    dd_expandfile(hdr.dataLength, hdr.dataCLength, (int)hdr.datamethod, 
  10731. X    (int)hdr.datainfo, data, (unsigned long)hdr.datacrc);
  10732. X    data += hdr.dataCLength;
  10733. X    if(write_it) {
  10734. X    if((hdr.info2 & 0x40) && (hdr.dataLength != 0)) {
  10735. X        cks = arc_updcrc(INIT_CRC, (unsigned char *)out_buf,
  10736. X                 (int)hdr.dataLength);
  10737. X        if(cks != hdr.datacrc2) {
  10738. X        (void)fprintf(stderr,
  10739. X            "Checksum error on data fork: need 0x%04x, got 0x%04x\n",
  10740. X            (int)hdr.datacrc2, (int)cks);
  10741. X#ifdef SCAN
  10742. X        do_error("macunpack: Checksum error on data fork");
  10743. X#endif /* SCAN */
  10744. X        exit(1);
  10745. X        }
  10746. X    }
  10747. X    }
  10748. X    if(verbose) {
  10749. X    (void)fprintf(stderr, ", Rsrc: ");
  10750. X    }
  10751. X    if(write_it) {
  10752. X    start_rsrc();
  10753. X    }
  10754. X    out_buf = out_buffer;
  10755. X    dd_expandfile(hdr.rsrcLength, hdr.rsrcCLength, (int)hdr.rsrcmethod,
  10756. X    (int)hdr.rsrcinfo, data, (unsigned long)hdr.rsrccrc);
  10757. X    data += hdr.rsrcCLength;
  10758. X    if(write_it) {
  10759. X    if((hdr.info2 & 0x40) && (hdr.rsrcLength != 0)) {
  10760. X        cks = arc_updcrc(INIT_CRC, (unsigned char *)out_buf,
  10761. X                 (int)hdr.rsrcLength);
  10762. X        if(cks != hdr.rsrccrc2) {
  10763. X        (void)fprintf(stderr,
  10764. X           "Checksum error on resource fork: need 0x%04x, got 0x%04x\n",
  10765. X            (int)hdr.rsrccrc2, (int)cks);
  10766. X#ifdef SCAN
  10767. X        do_error("macunpack: Checksum error on resource fork");
  10768. X#endif /* SCAN */
  10769. X        exit(1);
  10770. X        }
  10771. X    }
  10772. X    end_file();
  10773. X    }
  10774. X    if(verbose) {
  10775. X    (void)fprintf(stderr, ".\n");
  10776. X    }
  10777. X}
  10778. X
  10779. Xstatic void dd_expandfile(obytes, ibytes, method, kind, data, chksum)
  10780. Xunsigned long obytes, ibytes, chksum;
  10781. Xint method, kind;
  10782. Xunsigned char *data;
  10783. X{
  10784. X    int sub_method, m1, m2;
  10785. X    char *optr = out_ptr;
  10786. X    unsigned long cksinit;
  10787. X
  10788. X    if(obytes == 0) {
  10789. X    if(verbose) {
  10790. X        (void)fprintf(stderr, "empty");
  10791. X    }
  10792. X    return;
  10793. X    }
  10794. X    switch(method & 0x7f) {
  10795. X    case nocomp:
  10796. X    if(verbose) {
  10797. X        (void)fprintf(stderr, "No compression");
  10798. X    }
  10799. X    if(write_it) {
  10800. X        dd_nocomp(obytes, data);
  10801. X    }
  10802. X    break;
  10803. X    case lzc:
  10804. X    m1 = (*data++ & BYTEMASK) ^ dd_xor;
  10805. X    m2 = (*data++ & BYTEMASK) ^ dd_xor;
  10806. X    sub_method = (*data++ & BYTEMASK) ^ dd_xor;
  10807. X    cksinit = m1 + m2 + sub_method;
  10808. X    sub_method = sub_method & 0x1f;
  10809. X    if(verbose) {
  10810. X        (void)fprintf(stderr, "LZC(%d) compressed (%4.1f%%)",
  10811. X            sub_method, 100.0 * ibytes / obytes);
  10812. X    }
  10813. X    if(write_it) {
  10814. X        dd_lzc(ibytes - 3, obytes, data, sub_method, chksum, cksinit);
  10815. X    }
  10816. X    break;
  10817. X#ifdef UNTESTED
  10818. X    case rle:
  10819. X    if(verbose) {
  10820. X        (void)fprintf(stderr, "RLE compressed (%4.1f%%)",
  10821. X            100.0 * ibytes / obytes);
  10822. X    }
  10823. X    if(write_it) {
  10824. X        dd_rle(ibytes, data);
  10825. X    }
  10826. X    break;
  10827. X#ifdef NOTIMPLEMENTED
  10828. X    case huffman:
  10829. X    if(verbose) {
  10830. X        (void)fprintf(stderr, "Huffman compressed (%4.1f%%)",
  10831. X            100.0 * ibytes / obytes);
  10832. X    }
  10833. X    if(write_it) {
  10834. X        dd_huffman(ibytes, data);
  10835. X    }
  10836. X    break;
  10837. X#endif /* NOTIMPLEMENTED */
  10838. X    case lzss:
  10839. X    if(verbose) {
  10840. X        (void)fprintf(stderr, "LZSS compressed (%4.1f%%)",
  10841. X            100.0 * ibytes / obytes);
  10842. X    }
  10843. X    if(write_it) {
  10844. X        dd_lzss(data, chksum);
  10845. X    }
  10846. X    break;
  10847. X#endif /* UNTESTED */
  10848. X    case cpt_compat:
  10849. X    sub_method = get2((char *)data);
  10850. X    data += 16;
  10851. X    if(sub_method != 0) {
  10852. X        sub_method = 0;
  10853. X    } else {
  10854. X        sub_method = 1;
  10855. X    }
  10856. X    if(verbose) {
  10857. X        if(!sub_method) {
  10858. X        (void)fprintf(stderr, "RLE compressed (%4.1f%%)",
  10859. X            100.0 * ibytes / obytes);
  10860. X        } else {
  10861. X        (void)fprintf(stderr, "RLE/LZH compressed (%4.1f%%)",
  10862. X            100.0 * ibytes / obytes);
  10863. X        }
  10864. X    }
  10865. X    if(write_it) {
  10866. X        dd_cpt_compat(ibytes, obytes, data, sub_method, chksum);
  10867. X    }
  10868. X    break;
  10869. X    default:
  10870. X    break;
  10871. X    }
  10872. X    if(write_it) {
  10873. X    dd_do_delta(optr, obytes, kind);
  10874. X    }
  10875. X}
  10876. X
  10877. X/*---------------------------------------------------------------------------*/
  10878. X/*    Method 0: no compression                         */
  10879. X/*---------------------------------------------------------------------------*/
  10880. Xstatic void dd_nocomp(obytes, data)
  10881. Xunsigned char *data;
  10882. Xunsigned long obytes;
  10883. X{
  10884. X    copy(out_ptr, (char *)data, (int)obytes);
  10885. X}
  10886. X
  10887. X/*---------------------------------------------------------------------------*/
  10888. X/*    Method 1: LZC compressed                         */
  10889. X/*---------------------------------------------------------------------------*/
  10890. Xstatic void dd_lzc(ibytes, obytes, data, mb, chksum, ckinit)
  10891. Xunsigned char *data;
  10892. Xunsigned long ibytes, obytes, chksum, ckinit;
  10893. Xint mb;
  10894. X{
  10895. X    int i;
  10896. X    char *out_buf;
  10897. X    unsigned long cks;
  10898. X
  10899. X    out_buf = out_buffer;
  10900. X    core_compress((char *)data);
  10901. X    de_compress(ibytes, mb);
  10902. X    out_buffer = out_buf;
  10903. X    if(dd_xor != 0) {
  10904. X    for(i = 0; i < obytes; i++) {
  10905. X        *out_buf++ ^= dd_xor;
  10906. X    }
  10907. X    }
  10908. X    cks = dd_checksum(ckinit, out_buffer, obytes);
  10909. X    if(chksum != cks) {
  10910. X    (void)fprintf(stderr,
  10911. X        "Checksum error on fork: need 0x%04x, got 0x%04x\n",
  10912. X        (int)chksum, (int)cks);
  10913. X#ifdef SCAN
  10914. X    do_error("macunpack: Checksum error on fork");
  10915. X#endif /* SCAN */
  10916. X    exit(1);
  10917. X    }
  10918. X}
  10919. X
  10920. X#ifdef UNTESTED
  10921. X/*---------------------------------------------------------------------------*/
  10922. X/*    Method 3: Run length encoding                         */
  10923. X/*---------------------------------------------------------------------------*/
  10924. Xstatic void dd_rle(ibytes, data)
  10925. Xunsigned char *data;
  10926. Xunsigned long ibytes;
  10927. X{
  10928. X    int ch, lastch, n, i;
  10929. X
  10930. X    while(ibytes != 0) {
  10931. X    ch = *data++;
  10932. X    ibytes--;
  10933. X    if(ch == ESC) {
  10934. X        n = *data++ - 1;
  10935. X        ibytes--;
  10936. X        if(n < 0) {
  10937. X        *out_ptr++ = ESC;
  10938. X        lastch = ESC;
  10939. X        } else {
  10940. X        for(i = 0; i < n; i++) {
  10941. X            *out_ptr++ = lastch;
  10942. X        }
  10943. X        }
  10944. X    } else {
  10945. X        *out_ptr++ = ch;
  10946. X        lastch = ch;
  10947. X    }
  10948. X    }
  10949. X}
  10950. X
  10951. X#ifdef NOTIMPLEMENTED
  10952. X/*---------------------------------------------------------------------------*/
  10953. X/*    Method 4: Huffman encoding                         */
  10954. X/*---------------------------------------------------------------------------*/
  10955. Xstatic void dd_huffman(ibytes, data)
  10956. Xunsigned char *data;
  10957. Xunsigned long ibytes;
  10958. X{
  10959. X}
  10960. X#endif /* NOTIMPLEMENTED */
  10961. X
  10962. X/*---------------------------------------------------------------------------*/
  10963. X/*    Method 7: Slightly improved LZSS                     */
  10964. X/*---------------------------------------------------------------------------*/
  10965. Xstatic void dd_lzss(data, chksum)
  10966. Xunsigned char *data;
  10967. Xunsigned long chksum;
  10968. X{
  10969. X    int i, LZptr, LZbptr, LZlength;
  10970. X    char *optr = out_ptr;
  10971. X    unsigned char cks;
  10972. X
  10973. X    data += get4((char *)data + 6);
  10974. X    LZptr = 0;
  10975. X    while(1) {
  10976. X    if(dd_getbits(1) == 0) {
  10977. X        *out_ptr++ = dd_LZbuff[LZptr++] = dd_getbits(8);
  10978. X        LZptr &= 0x7ff;
  10979. X    } else {
  10980. X        if(dd_getbits(1) == 0) {
  10981. X        LZbptr = dd_getbits(11);
  10982. X        } else {
  10983. X        LZbptr = dd_getbits(7);
  10984. X        }
  10985. X        if(LZbptr == 0) {
  10986. X        break;
  10987. X        }
  10988. X        LZbptr = (LZptr - LZbptr) & 0x7ff;
  10989. X        LZlength = dd_getbits(2);
  10990. X        if(LZlength == 3) {
  10991. X        LZlength += dd_getbits(2);
  10992. X        if(LZlength == 6) {
  10993. X            do {
  10994. X            i = dd_getbits(4);
  10995. X            LZlength += i;
  10996. X            } while(i == 15);
  10997. X        }
  10998. X        }
  10999. X        LZlength += 2;
  11000. X        for(i = 0; i < LZlength; i++) {
  11001. X        *out_ptr++ = dd_LZbuff[LZptr++] = dd_LZbuff[LZbptr++];
  11002. X        LZptr &= 0x7ff;
  11003. X        LZbptr &= 0x7ff;
  11004. X        }
  11005. X    }
  11006. X    }
  11007. X    cks = dd_checkor(INIT_CRC, optr, (unsigned long)(out_ptr - optr));
  11008. X    if(chksum != cks) {
  11009. X    (void)fprintf(stderr,
  11010. X        "Checksum error on fork: need 0x%04x, got 0x%04x\n",
  11011. X        chksum, (int)cks);
  11012. X#ifdef SCAN
  11013. X    do_error("macunpack: Checksum error on fork");
  11014. X#endif /* SCAN */
  11015. X    exit(1);
  11016. X    }
  11017. X}
  11018. X
  11019. Xstatic int dd_getbits(n)
  11020. Xint n;
  11021. X{
  11022. X    int r;
  11023. X
  11024. X    while(dd_bitcount < n) {
  11025. X    dd_bitbuf = (dd_bitbuf << 8) | (~(*dd_bitptr++) & BYTEMASK);
  11026. X    dd_bitcount += 8;
  11027. X    }
  11028. X    dd_bitcount -= n;
  11029. X    r = (dd_bitbuf >> dd_bitcount);
  11030. X    dd_bitbuf ^= (r << dd_bitcount);
  11031. X    return r;
  11032. X}
  11033. X
  11034. X#endif /* UNTESTED */
  11035. X
  11036. X/*---------------------------------------------------------------------------*/
  11037. X/*    Method 8: Compactor compatible compression                 */
  11038. X/*---------------------------------------------------------------------------*/
  11039. Xstatic void dd_cpt_compat(ibytes, obytes, data, sub_method, chksum)
  11040. Xunsigned char *data;
  11041. Xunsigned long ibytes, obytes, chksum;
  11042. Xint sub_method;
  11043. X{
  11044. X    unsigned long cks;
  11045. X    char *optr = out_buffer;
  11046. X
  11047. X    cpt_wrfile1(data, ibytes, obytes, sub_method, (unsigned long)0x0fff0);
  11048. X    cks = arc_updcrc(INIT_CRC, (unsigned char *)optr, (int)obytes);
  11049. X    if(chksum != cks) {
  11050. X    (void)fprintf(stderr,
  11051. X        "Checksum error on fork: need 0x%04x, got 0x%04x\n",
  11052. X        (int)chksum, (int)cks);
  11053. X#ifdef SCAN
  11054. X    do_error("macunpack: Checksum error on fork");
  11055. X#endif /* SCAN */
  11056. X    exit(1);
  11057. X    }
  11058. X}
  11059. X#else /* DD */
  11060. Xint dd; /* keep lint and some compilers happy */
  11061. X#endif /* DD */
  11062. X
  11063. SHAR_EOF
  11064. if test 25074 -ne "`wc -c < 'dd.c'`"
  11065. then
  11066.     echo shar: "error transmitting 'dd.c'" '(should have been 25074 characters)'
  11067. fi
  11068. fi
  11069. echo shar: "done with directory 'macunpack'"
  11070. cd ..
  11071. echo shar: "extracting 'makefile'" '(1609 characters)'
  11072. if test -f 'makefile'
  11073. then
  11074.     echo shar: "will not over-write existing file 'makefile'"
  11075. else
  11076. sed 's/^X//' << \SHAR_EOF > 'makefile'
  11077. XSHELL =    /bin/sh
  11078. XBINDIR =    /ufs/dik/tmpbin
  11079. X# Use the following flags on the CF macro definition as needed.
  11080. X#
  11081. X# -DBSD if you are on a BSD system
  11082. X#
  11083. X# -DTYPES_H if your system has /usr/include/sys/types.h
  11084. X#
  11085. X# -DDIRENT_H if your system has /usr/include/dirent.h
  11086. X#
  11087. X# -DNODOT if you do not want to create files with an initial period
  11088. X#
  11089. X# -DLATIN1 if your system supports LATIN-1 and you want to use it
  11090. X#
  11091. X# Note you can use at most one of the following four!
  11092. X#
  11093. X# -DNOMKDIR if your system does not have the mkdir system call
  11094. X#
  11095. X# -DAUFS if you want to use an AUFS file system
  11096. X#
  11097. X# -DAUFSPLUS if you use CAP 6.0 and want to use times on files
  11098. X#
  11099. X# -DAPPLEDOUBLE if you want to be able to use an AppleDouble file system
  11100. X#
  11101. XCF =    -DBSD -DTYPES_H -DDIRENT_H -DNODOT -DAPPLEDOUBLE
  11102. X
  11103. Xall:
  11104. X    (cd crc; make CF='$(CF)')
  11105. X    (cd util; make CF='$(CF)')
  11106. X    (cd fileio; make CF='$(CF)')
  11107. X    (cd macunpack; make CF='$(CF)')
  11108. X    (cd hexbin; make CF='$(CF)')
  11109. X    (cd mixed; make CF='$(CF)')
  11110. X
  11111. Xclean:
  11112. X    (cd crc; make clean)
  11113. X    (cd util; make clean)
  11114. X    (cd fileio; make clean)
  11115. X    (cd macunpack; make clean)
  11116. X    (cd hexbin; make clean)
  11117. X    (cd mixed; make clean)
  11118. X
  11119. Xclobber:
  11120. X    (cd crc; make clean)
  11121. X    (cd util; make clean)
  11122. X    (cd fileio; make clean)
  11123. X    (cd macunpack; make clobber)
  11124. X    (cd hexbin; make clobber)
  11125. X    (cd mixed; make clobber)
  11126. X
  11127. Xlint:
  11128. X    (cd macunpack; make CF='$(CF)' lint)
  11129. X    (cd hexbin; make CF='$(CF)' lint)
  11130. X    (cd mixed; make CF='$(CF)' lint)
  11131. X
  11132. Xinstall:
  11133. X    cp macunpack/macunpack $(BINDIR)/.
  11134. X    cp hexbin/hexbin $(BINDIR)/.
  11135. X    cp mixed/macsave $(BINDIR)/.
  11136. X    cp mixed/macstream $(BINDIR)/.
  11137. X
  11138. Xdistr:
  11139. X    shar -a README makefile crc util fileio macunpack hexbin mixed doc man >macutil.shar
  11140. X
  11141. SHAR_EOF
  11142. if test 1609 -ne "`wc -c < 'makefile'`"
  11143. then
  11144.     echo shar: "error transmitting 'makefile'" '(should have been 1609 characters)'
  11145. fi
  11146. fi
  11147. if test ! -d 'hexbin'
  11148. then
  11149.     echo shar: "creating directory 'hexbin'"
  11150.     mkdir 'hexbin'
  11151. fi
  11152. echo shar: "entering directory 'hexbin'"
  11153. cd 'hexbin'
  11154. echo shar: "extracting 'hexbin.c'" '(7767 characters)'
  11155. if test -f 'hexbin.c'
  11156. then
  11157.     echo shar: "will not over-write existing file 'hexbin.c'"
  11158. else
  11159. sed 's/^X//' << \SHAR_EOF > 'hexbin.c'
  11160. X#ifdef TYPES_H
  11161. X#include <sys/types.h>
  11162. X#endif /* TYPES_H */
  11163. X#include <sys/stat.h>
  11164. X#include "globals.h"
  11165. X#include "crc.h"
  11166. X#include "readline.h"
  11167. X#include "../util/masks.h"
  11168. X#include "../util/util.h"
  11169. X#include "../util/patchlevel.h"
  11170. X#include "../fileio/wrfile.h"
  11171. X#include "../fileio/wrfileopt.h"
  11172. X#include "../fileio/machdr.h"
  11173. X#include "../fileio/kind.h"
  11174. X#include "../util/curtime.h"
  11175. X#include "hexbin.h"
  11176. X
  11177. X#define LOCALOPT    "ilvcn:qVH"
  11178. X
  11179. Xextern void exit();
  11180. Xextern void backtrans();
  11181. X#ifdef DL
  11182. Xextern void dl();
  11183. X#endif /* DL */
  11184. X#ifdef HECX
  11185. Xextern void hecx();
  11186. X#endif /* HECX */
  11187. X#ifdef HQX
  11188. Xextern void hqx();
  11189. X#endif /* HQX */
  11190. X#ifdef MU
  11191. Xextern void mu();
  11192. X#endif /* MU */
  11193. X
  11194. Xstatic void usage();
  11195. Xstatic void do_files();
  11196. Xstatic int find_header();
  11197. X
  11198. Xstatic char options[128];
  11199. X
  11200. Xint main(argc, argv)
  11201. Xint argc;
  11202. Xchar **argv;
  11203. X{
  11204. X    char *filename;
  11205. X    char macname[32];
  11206. X    extern int optind;
  11207. X    extern char *optarg;
  11208. X    int errflg;
  11209. X    int c;
  11210. X
  11211. X    set_wrfileopt(0);
  11212. X    (void)strcat(options, get_wrfileopt());
  11213. X    (void)strcat(options, LOCALOPT);
  11214. X    errflg = 0;
  11215. X    filename = "";
  11216. X    macname[0] = 0;
  11217. X
  11218. X    while((c = getopt(argc, argv, options)) != EOF) {
  11219. X    if(!wrfileopt((char)c)) {
  11220. X        switch(c) {
  11221. X        case 'l':
  11222. X        listmode++;
  11223. X        break;
  11224. X        case 'v':
  11225. X        verbose++;
  11226. X        break;
  11227. X        case 'i':
  11228. X        info_only++;
  11229. X        break;
  11230. X        case 'c':
  11231. X        uneven_lines++;
  11232. X        break;
  11233. X        case 'n':
  11234. X        backtrans(macname, optarg);
  11235. X        break;
  11236. X        case '?':
  11237. X        errflg++;
  11238. X        break;
  11239. X        case 'H':
  11240. X        give_wrfileopt();
  11241. X        (void)fprintf(stderr, "Hexbin specific options:\n");
  11242. X        (void)fprintf(stderr,
  11243. X            "-i:\tgive information only, do not convert\n");
  11244. X        (void)fprintf(stderr, "-l:\tgive listing\n");
  11245. X        (void)fprintf(stderr,
  11246. X            "-v:\tgive verbose listing, including lines skipped\n");
  11247. X        (void)fprintf(stderr,
  11248. X            "-c:\tdo not check for equal line lengths\n");
  11249. X        (void)fprintf(stderr, "-n nm:\tname to be generated\n");
  11250. X        (void)fprintf(stderr,
  11251. X            "-V:\tgive information about this version\n");
  11252. X        (void)fprintf(stderr, "-H:\tthis message\n");
  11253. X        (void)fprintf(stderr, "Default is silent conversion\n");
  11254. X        exit(0);
  11255. X        case 'V':
  11256. X        (void)fprintf(stderr, "Version %s, ", VERSION);
  11257. X        (void)fprintf(stderr, "patchlevel %d", PATCHLEVEL);
  11258. X        (void)fprintf(stderr, "%s.\n", get_mina());
  11259. X        (void)fprintf(stderr, "Hexified files recognized:\n");
  11260. X#ifdef DL
  11261. X        (void)fprintf(stderr, "\tDownload (.dl)\n");
  11262. X#endif /* DL */
  11263. X#ifdef HECX
  11264. X        (void)fprintf(stderr, "\tBinHex 2.0 (.hex)\n");
  11265. X        (void)fprintf(stderr, "\tBinHex 3.0 (.hcx)\n");
  11266. X#endif /* HECX */
  11267. X#ifdef HQX
  11268. X        (void)fprintf(stderr, "\tBinHex 4.0 (.hqx)\n");
  11269. X#endif /* HQX */
  11270. X#ifdef MU
  11271. X        (void)fprintf(stderr, "\tUUTool (.mu)\n");
  11272. X#endif /* MU */
  11273. X        exit(0);
  11274. X        }
  11275. X    }
  11276. X    }
  11277. X    if(errflg) {
  11278. X    usage();
  11279. X    exit(1);
  11280. X    }
  11281. X    if(info_only || verbose) {
  11282. X    listmode++;
  11283. X    }
  11284. X
  11285. X    do {
  11286. X    if(optind == argc) {
  11287. X        filename = "-";
  11288. X    } else {
  11289. X        filename = argv[optind];
  11290. X        optind++;
  11291. X#ifdef SCAN
  11292. X        do_idf(filename, UNIX_NAME);
  11293. X#endif /* SCAN */
  11294. X    }
  11295. X    do_files(filename, macname);
  11296. X    } while(optind < argc);
  11297. X    exit(0);
  11298. X    /* NOTREACHED */
  11299. X}
  11300. X
  11301. Xstatic char *extensions[] = {
  11302. X#ifdef DL
  11303. X    ".dl",
  11304. X#endif /* DL */
  11305. X#ifdef HECX
  11306. X    ".hex",
  11307. X    ".Hex",
  11308. X    ".hcx",
  11309. X    ".Hcx",
  11310. X#endif /* HECX */
  11311. X#ifdef HQX
  11312. X    ".hqx",
  11313. X    ".Hqx",
  11314. X#endif /* HQX */
  11315. X#ifdef MU
  11316. X    ".mu",
  11317. X#endif /* MU */
  11318. X    "",
  11319. X    NULL
  11320. X};
  11321. X
  11322. Xstatic void do_files(filename, macname)
  11323. Xchar *filename;    /* input file name -- extension optional */
  11324. Xchar *macname;    /* name to use on the mac side of things */
  11325. X{
  11326. X    char namebuf[256];
  11327. X    char **ep;
  11328. X    struct stat stbuf;
  11329. X    long curtime;
  11330. X    int qformat;
  11331. X    int again;
  11332. X
  11333. X    if(filename[0] == '-') {
  11334. X    ifp = stdin;
  11335. X    filename = "stdin";
  11336. X    } else {
  11337. X    /* find input file and open it */
  11338. X    for(ep = extensions; *ep != NULL; ep++) {
  11339. X        (void)sprintf(namebuf, "%s%s", filename, *ep);
  11340. X        if(stat(namebuf, &stbuf) == 0) {
  11341. X        break;
  11342. X        }
  11343. X    }
  11344. X    if(*ep == NULL) {
  11345. X        perror(namebuf);
  11346. X        exit(1);
  11347. X    }
  11348. X    ifp = fopen(namebuf, "r");
  11349. X    if(ifp == NULL) {
  11350. X        perror(namebuf);
  11351. X        exit(1);
  11352. X    }
  11353. X    }
  11354. X    again = 0;
  11355. Xnexttry:
  11356. X    if(ifp == stdin) {
  11357. X    curtime = (long)time((time_t *)0) + TIMEDIFF;
  11358. X    mh.m_createtime = curtime;
  11359. X    mh.m_modifytime = curtime;
  11360. X    } else {
  11361. X    mh.m_createtime = stbuf.st_mtime + TIMEDIFF;
  11362. X    mh.m_modifytime = stbuf.st_mtime + TIMEDIFF;
  11363. X    }
  11364. X
  11365. X    qformat = find_header(again); /* eat mailer header &cetera, intuit format */
  11366. X
  11367. X    switch (qformat) {
  11368. X#ifdef DL
  11369. X    case form_dl:
  11370. X    dl(macname, filename);
  11371. X    break;
  11372. X#endif /* DL */
  11373. X#ifdef HECX
  11374. X    case form_hecx:
  11375. X    hecx(macname, filename);
  11376. X    break;
  11377. X#endif /* HECX */
  11378. X#ifdef HQX
  11379. X    case form_hqx:
  11380. X    hqx(macname);
  11381. X    again = 1;
  11382. X    goto nexttry;
  11383. X#endif /* HQX */
  11384. X#ifdef MU
  11385. X    case form_mu:
  11386. X    mu(macname);
  11387. X    again = 1;
  11388. X    goto nexttry;
  11389. X#endif /* MU */
  11390. X    default:
  11391. X    break;
  11392. X    }
  11393. X    (void)fclose(ifp);
  11394. X}
  11395. X
  11396. X/* eat characters until header detected, return which format */
  11397. Xstatic int find_header(again)
  11398. Xint again;
  11399. X{
  11400. X    int c, dl_start, llen;
  11401. X    char *cp;
  11402. X    char header[INFOBYTES];
  11403. X    int ds, rs;
  11404. X
  11405. X    if(again && was_macbin) {
  11406. X    while(to_read-- > 0) {
  11407. X        c = fgetc(ifp);
  11408. X    }
  11409. X    }
  11410. X    was_macbin = 0;
  11411. X    c = fgetc(ifp);
  11412. X    (void)ungetc(c, ifp);
  11413. X    if(c == 0) {
  11414. X    was_macbin = 1;
  11415. X    if(fread(header, 1, INFOBYTES, ifp) != INFOBYTES) {
  11416. X        (void)fprintf(stderr, "Premature EOF\n");
  11417. X#ifdef SCAN
  11418. X        do_error("hexbin: Premature EOF");
  11419. X#endif /* SCAN */
  11420. X        exit(1);
  11421. X    }
  11422. X    ds = get4(header + I_DLENOFF);
  11423. X    rs = get4(header + I_RLENOFF);
  11424. X    ds = (((ds + 127) >> 7) << 7);
  11425. X    rs = (((rs + 127) >> 7) << 7);
  11426. X    to_read = ds + rs;
  11427. X    if(strncmp(header + I_TYPEOFF, "TEXT", 4)) {
  11428. X        (void)fprintf(stderr, "This file is not a proper BinHexed file.\n");
  11429. X#ifdef SCAN
  11430. X        do_error("hexbin: not a proper BinHexed file");
  11431. X#endif /* SCAN */
  11432. X        exit(1);
  11433. X    }
  11434. X    if(listmode) {
  11435. X        (void)fprintf(stderr, "This file is probably packed by ");
  11436. X        if(!strncmp(header + I_AUTHOFF, "BNHQ", 4)) {
  11437. X        (void)fprintf(stderr, "\"BinHex\"");
  11438. X        } else if(!strncmp(header + I_AUTHOFF, "BthX", 4)) {
  11439. X        (void)fprintf(stderr, "\"BinHqx\"");
  11440. X        } else if(!strncmp(header + I_AUTHOFF, "BnHq", 4)) {
  11441. X        (void)fprintf(stderr, "\"StuffIt\"");
  11442. X        } else if(!strncmp(header + I_AUTHOFF, "ttxt", 4)) {
  11443. X        (void)fprintf(stderr, "\"Compactor\"");
  11444. X        } else if(!strncmp(header + I_AUTHOFF, "BSWU", 4)) {
  11445. X        (void)fprintf(stderr, "\"UUTool\"");
  11446. X        } else {
  11447. X        (void)fprintf(stderr, "an unknown program");
  11448. X        }
  11449. X        (void)fprintf(stderr, ".\n");
  11450. X    }
  11451. X    }
  11452. X    /*    look for "(This file ...)" or "(Convert with...)" line. */
  11453. X    /*    or for "begin " */
  11454. X    /*    dl format starts with a line containing only the symbols '@' to 'O',
  11455. X    or '|'. */
  11456. X    while(readline()) {
  11457. X    llen = strlen(line);
  11458. X#ifdef HQX
  11459. X    if((strncmp(line, "(This file", 10) == 0) ||
  11460. X        (strncmp(line, "(Convert with", 13) == 0)) {
  11461. X        if(verbose) {
  11462. X        (void)fprintf(stderr, "Skip:%s\n", line);
  11463. X        }
  11464. X        break;
  11465. X    }
  11466. X#endif /* HQX */
  11467. X#ifdef MU
  11468. X    if(strncmp(line, "begin ", 6) == 0) {
  11469. X        return form_mu;
  11470. X    }
  11471. X#endif /* MU */
  11472. X#ifdef DL
  11473. X    /* Do not allow bogus false starts */
  11474. X    if(llen > 40 && (llen & 1) == 0) {
  11475. X        dl_start = 1;
  11476. X        for(cp = &line[0]; *cp != 0; cp++) {
  11477. X        if((*cp < '@' || *cp > 'O') && *cp != '|') {
  11478. X            dl_start = 0;
  11479. X            break;
  11480. X        }
  11481. X        }
  11482. X        if(dl_start && cp > &line[1]) {
  11483. X        return form_dl;
  11484. X        }
  11485. X    }
  11486. X#endif /* DL */
  11487. X    if(llen != 0 && verbose) {
  11488. X        (void)fprintf(stderr, "Skip:%s\n", line);
  11489. X    }
  11490. X    }
  11491. X    while(readline()) {
  11492. X    switch (line[0]) {
  11493. X#ifdef HQX
  11494. X    case ':':
  11495. X        return form_hqx;
  11496. X#endif /* HQX */
  11497. X#ifdef HECX
  11498. X    case '#':
  11499. X        return form_hecx;
  11500. X#endif /* HECX */
  11501. X    default:
  11502. X        break;
  11503. X    }
  11504. X    }
  11505. X
  11506. X    if(!again) {
  11507. X    (void)fprintf(stderr, "unexpected EOF\n");
  11508. X#ifdef SCAN
  11509. X    do_error("hexbin: unexpected EOF");
  11510. X#endif /* SCAN */
  11511. X    exit(1);
  11512. X    }
  11513. X    return form_none;
  11514. X}
  11515. X
  11516. Xstatic void usage()
  11517. X{
  11518. X    (void)fprintf(stderr, "Usage: hexbin [-%s] [filenames]\n", options);
  11519. X    (void)fprintf(stderr, "Use \"hexbin -H\" for help.\n");
  11520. X}
  11521. X
  11522. SHAR_EOF
  11523. if test 7767 -ne "`wc -c < 'hexbin.c'`"
  11524. then
  11525.     echo shar: "error transmitting 'hexbin.c'" '(should have been 7767 characters)'
  11526. fi
  11527. fi
  11528. echo shar: "extracting 'makefile'" '(2504 characters)'
  11529. if test -f 'makefile'
  11530. then
  11531.     echo shar: "will not over-write existing file 'makefile'"
  11532. else
  11533. sed 's/^X//' << \SHAR_EOF > 'makefile'
  11534. XCFLAGS=    -O $(CF)
  11535. X
  11536. XSRCS =    hexbin.c \
  11537. X    dl.c \
  11538. X    hecx.c \
  11539. X    hqx.c \
  11540. X    mu.c \
  11541. X    buffer.c \
  11542. X    crc.c \
  11543. X    readline.c \
  11544. X    printhdr.c \
  11545. X    globals.c
  11546. X
  11547. XOBJS =    hexbin.o \
  11548. X    dl.o \
  11549. X    hecx.o \
  11550. X    hqx.o \
  11551. X    mu.o \
  11552. X    buffer.o \
  11553. X    crc.o \
  11554. X    readline.o \
  11555. X    printhdr.o \
  11556. X    globals.o
  11557. X
  11558. XLIB =    ../crc/libcrc.a
  11559. XTNAME =    ../util/transname
  11560. XBNAME =    ../util/backtrans
  11561. XUNAME =    ../util/util
  11562. XONAME =    ../fileio/wrfile
  11563. XGNAME =    ../fileio/fileglob
  11564. XXOBJS =    $(TNAME).o $(BNAME).o $(UNAME).o $(ONAME).o $(GNAME).o
  11565. XXSRCS =    $(TNAME).c $(BNAME).c $(UNAME).c $(ONAME).c $(GNAME).c
  11566. XCRCS =    ../crc/binhex.c
  11567. X
  11568. Xhexbin:    $(OBJS) $(LIB) $(XOBJS)
  11569. X    $(CC) $(CFLAGS) -o hexbin $(OBJS) $(XOBJS) $(LIB)
  11570. X
  11571. X$(LIB):    ../crc/makecrc.c
  11572. X    (cd ../crc; make CC=$(CC) CF="$(CF)" )
  11573. X
  11574. X$(TNAME).o:    $(TNAME).c
  11575. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  11576. X
  11577. X$(BNAME).o:    $(BNAME).c
  11578. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  11579. X
  11580. X$(UNAME).o:    $(UNAME).c
  11581. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  11582. X
  11583. X$(ONAME).o:    $(ONAME).c
  11584. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  11585. X
  11586. X$(GNAME).o:    $(GNAME).c
  11587. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  11588. X
  11589. Xlint:
  11590. X    lint $(CF) $(LFLAGS) $(SRCS) $(XSRCS) $(CRCS)
  11591. X
  11592. Xclean:
  11593. X    -rm -f *.o
  11594. X
  11595. Xclobber:clean
  11596. X    -rm -f hexbin
  11597. X
  11598. Xhexbin.o:    globals.h
  11599. Xhexbin.o:    crc.h
  11600. Xhexbin.o:    readline.h
  11601. Xhexbin.o:    ../util/masks.h
  11602. Xhexbin.o:    ../util/util.h
  11603. Xhexbin.o:    ../util/patchlevel.h
  11604. Xhexbin.o:    ../fileio/wrfile.h
  11605. Xhexbin.o:    ../fileio/wrfileopt.h
  11606. Xhexbin.o:    ../fileio/machdr.h
  11607. Xhexbin.o:    ../fileio/kind.h
  11608. Xhexbin.o:    ../util/curtime.h
  11609. Xhexbin.o:    hexbin.h
  11610. Xdl.o:    hexbin.h
  11611. Xdl.o:    globals.h
  11612. Xdl.o:    crc.h
  11613. Xdl.o:    readline.h
  11614. Xdl.o:    ../fileio/machdr.h
  11615. Xdl.o:    ../fileio/wrfile.h
  11616. Xdl.o:    ../util/util.h
  11617. Xdl.o:    buffer.h
  11618. Xdl.o:    printhdr.h
  11619. Xhecx.o:    hexbin.h
  11620. Xhecx.o:    globals.h
  11621. Xhecx.o:    crc.h
  11622. Xhecx.o:    readline.h
  11623. Xhecx.o:    ../util/masks.h
  11624. Xhecx.o:    ../util/util.h
  11625. Xhecx.o:    ../fileio/machdr.h
  11626. Xhecx.o:    ../fileio/wrfile.h
  11627. Xhecx.o:    buffer.h
  11628. Xhecx.o:    printhdr.h
  11629. Xhqx.o:    hexbin.h
  11630. Xhqx.o:    globals.h
  11631. Xhqx.o:    readline.h
  11632. Xhqx.o:    crc.h
  11633. Xhqx.o:    buffer.h
  11634. Xhqx.o:    ../fileio/machdr.h
  11635. Xhqx.o:    ../fileio/wrfile.h
  11636. Xhqx.o:    ../util/util.h
  11637. Xhqx.o:    printhdr.h
  11638. Xmu.o:    hexbin.h
  11639. Xmu.o:    globals.h
  11640. Xmu.o:    readline.h
  11641. Xmu.o:    ../util/masks.h
  11642. Xmu.o:    ../util/util.h
  11643. Xmu.o:    ../fileio/machdr.h
  11644. Xmu.o:    ../fileio/wrfile.h
  11645. Xmu.o:    buffer.h
  11646. Xmu.o:    printhdr.h
  11647. Xbuffer.o:    globals.h
  11648. Xbuffer.o:    ../util/util.h
  11649. Xbuffer.o:    buffer.h
  11650. Xbuffer.o:    ../fileio/wrfile.h
  11651. Xcrc.o:    hexbin.h
  11652. Xcrc.o:    crc.h
  11653. Xcrc.o:    ../util/masks.h
  11654. Xcrc.o:    globals.h
  11655. Xreadline.o:    readline.h
  11656. Xreadline.o:    globals.h
  11657. Xprinthdr.o:    printhdr.h
  11658. Xprinthdr.o:    globals.h
  11659. Xglobals.o:    globals.h
  11660. Xglobals.o:    ../fileio/machdr.h
  11661. Xglobals.o:    ../fileio/wrfile.h
  11662. Xglobals.o:    ../fileio/kind.h
  11663. X
  11664. SHAR_EOF
  11665. if test 2504 -ne "`wc -c < 'makefile'`"
  11666. then
  11667.     echo shar: "error transmitting 'makefile'" '(should have been 2504 characters)'
  11668. fi
  11669. fi
  11670. echo shar: "extracting 'crc.c'" '(757 characters)'
  11671. if test -f 'crc.c'
  11672. then
  11673.     echo shar: "will not over-write existing file 'crc.c'"
  11674. else
  11675. sed 's/^X//' << \SHAR_EOF > 'crc.c'
  11676. X/* crc.c; do crc calculation. */
  11677. X
  11678. X#include <stdio.h>
  11679. X#include "hexbin.h"
  11680. X#include "crc.h"
  11681. X#include "../util/masks.h"
  11682. X#include "globals.h"
  11683. X
  11684. Xextern void exit();
  11685. X
  11686. Xunsigned long crc;
  11687. X
  11688. X#ifdef HQX
  11689. Xvoid comp_q_crc(c)
  11690. Xregister unsigned int c;
  11691. X{
  11692. X    unsigned char cc = c;
  11693. X
  11694. X    crc = binhex_updcrc(crc, &cc, 1);
  11695. X}
  11696. X
  11697. Xvoid comp_q_crc_n(s, e)
  11698. Xregister unsigned char *s, *e;
  11699. X{
  11700. X    crc = binhex_updcrc(crc, s, e - s);
  11701. X}
  11702. X#endif /* HQX */
  11703. X
  11704. Xvoid verify_crc(calc_crc, file_crc)
  11705. Xunsigned long calc_crc, file_crc;
  11706. X{
  11707. X    calc_crc &= WORDMASK;
  11708. X    file_crc &= WORDMASK;
  11709. X
  11710. X    if(calc_crc != file_crc) {
  11711. X        (void)fprintf(stderr, "CRC mismatch: got 0x%04lx, need 0x%04lx\n",
  11712. X        file_crc, calc_crc);
  11713. X#ifdef SCAN
  11714. X    do_error("hexbin: CRC error");
  11715. X#endif /* SCAN */
  11716. X    exit(1);
  11717. X    }
  11718. X}
  11719. X
  11720. SHAR_EOF
  11721. if test 757 -ne "`wc -c < 'crc.c'`"
  11722. then
  11723.     echo shar: "error transmitting 'crc.c'" '(should have been 757 characters)'
  11724. fi
  11725. fi
  11726. echo shar: "extracting 'globals.c'" '(372 characters)'
  11727. if test -f 'globals.c'
  11728. then
  11729.     echo shar: "will not over-write existing file 'globals.c'"
  11730. else
  11731. sed 's/^X//' << \SHAR_EOF > 'globals.c'
  11732. X#include "globals.h"
  11733. X#include "../fileio/machdr.h"
  11734. X#include "../fileio/wrfile.h"
  11735. X#include "../fileio/kind.h"
  11736. X
  11737. Xstruct macheader mh;
  11738. X
  11739. Xchar info[INFOBYTES];
  11740. Xchar trname[64];
  11741. X
  11742. Xint listmode;
  11743. Xint info_only;
  11744. Xint verbose;
  11745. Xint uneven_lines;
  11746. Xint to_read;
  11747. Xint was_macbin;
  11748. X
  11749. XFILE *ifp;
  11750. X
  11751. X#ifdef SCAN
  11752. Xvoid do_error(string)
  11753. Xchar *string;
  11754. X{
  11755. X    do_idf(string, ERROR);
  11756. X}
  11757. X#endif /* SCAN */
  11758. X
  11759. SHAR_EOF
  11760. if test 372 -ne "`wc -c < 'globals.c'`"
  11761. then
  11762.     echo shar: "error transmitting 'globals.c'" '(should have been 372 characters)'
  11763. fi
  11764. fi
  11765. echo shar: "extracting 'globals.h'" '(636 characters)'
  11766. if test -f 'globals.h'
  11767. then
  11768.     echo shar: "will not over-write existing file 'globals.h'"
  11769. else
  11770. sed 's/^X//' << \SHAR_EOF > 'globals.h'
  11771. X#include <stdio.h>
  11772. X#include <string.h>
  11773. X#ifdef BSD
  11774. Xextern char *rindex();
  11775. X#define search_last rindex
  11776. X#else /* BSD */
  11777. Xextern char *strrchr();
  11778. X#define search_last strrchr
  11779. X#endif /* BSD */
  11780. X
  11781. Xextern void transname();
  11782. X
  11783. Xextern char info[];
  11784. Xextern char trname[];
  11785. X
  11786. Xtypedef struct macheader {
  11787. X    char m_name[128];
  11788. X    char m_type[4];
  11789. X    char m_author[4];
  11790. X    short m_flags;
  11791. X    long m_datalen;
  11792. X    long m_rsrclen;
  11793. X    long m_createtime;
  11794. X    long m_modifytime;
  11795. X};
  11796. X
  11797. Xextern struct macheader mh;
  11798. X
  11799. Xextern int listmode;
  11800. Xextern int verbose;
  11801. Xextern int info_only;
  11802. Xextern int uneven_lines;
  11803. Xextern int to_read;
  11804. Xextern int was_macbin;
  11805. X
  11806. Xextern FILE *ifp;
  11807. X
  11808. Xextern void do_error();
  11809. X
  11810. SHAR_EOF
  11811. if test 636 -ne "`wc -c < 'globals.h'`"
  11812. then
  11813.     echo shar: "error transmitting 'globals.h'" '(should have been 636 characters)'
  11814. fi
  11815. fi
  11816. echo shar: "extracting 'crc.h'" '(215 characters)'
  11817. if test -f 'crc.h'
  11818. then
  11819.     echo shar: "will not over-write existing file 'crc.h'"
  11820. else
  11821. sed 's/^X//' << \SHAR_EOF > 'crc.h'
  11822. X#define INITCRC binhex_crcinit
  11823. X
  11824. Xextern unsigned long crc;
  11825. Xextern unsigned long binhex_crcinit;
  11826. Xextern unsigned long binhex_updcrc();
  11827. X
  11828. Xextern void comp_q_crc();
  11829. Xextern void comp_q_crc_n();
  11830. Xextern void verify_crc();
  11831. X
  11832. SHAR_EOF
  11833. if test 215 -ne "`wc -c < 'crc.h'`"
  11834. then
  11835.     echo shar: "error transmitting 'crc.h'" '(should have been 215 characters)'
  11836. fi
  11837. fi
  11838. echo shar: "extracting 'dl.c'" '(2716 characters)'
  11839. if test -f 'dl.c'
  11840. then
  11841.     echo shar: "will not over-write existing file 'dl.c'"
  11842. else
  11843. sed 's/^X//' << \SHAR_EOF > 'dl.c'
  11844. X#include "hexbin.h"
  11845. X#ifdef DL
  11846. X#include "globals.h"
  11847. X#include "crc.h"
  11848. X#include "readline.h"
  11849. X#include "../fileio/machdr.h"
  11850. X#include "../fileio/wrfile.h"
  11851. X#include "../util/util.h"
  11852. X#include "buffer.h"
  11853. X#include "printhdr.h"
  11854. X
  11855. Xextern void exit();
  11856. X
  11857. Xstatic long dl_fork();
  11858. Xstatic int nchar();
  11859. Xstatic int nextc();
  11860. X
  11861. Xstatic char *icp = &line[0];
  11862. X
  11863. X/* oldest format -- process .dl files */
  11864. Xvoid dl(macname, filename)
  11865. Xchar *macname, *filename;
  11866. X{
  11867. X    int n;
  11868. X
  11869. X    if(listmode) {
  11870. X    (void)fprintf(stderr, "This file is in \"dl\" format.\n");
  11871. X    }
  11872. X    for(n = 0; n < INFOBYTES; n++) {
  11873. X    info[n] = 0;
  11874. X    }
  11875. X    /* set up for Mac name */
  11876. X    if(macname[0] == '\0') {
  11877. X    /* strip directories */
  11878. X    macname = search_last(filename, '/');
  11879. X    if(macname == NULL) {
  11880. X        macname = filename;
  11881. X    } else {
  11882. X        macname++;
  11883. X    }
  11884. X    /* strip extension */
  11885. X    n = strlen(macname);
  11886. X    if(n > 3) {
  11887. X        n -= 3;
  11888. X        if(!strncmp(macname + n, ".dl", 3)) {
  11889. X        macname[n] = '\0';
  11890. X        }
  11891. X    }
  11892. X    }
  11893. X    n = strlen(macname);
  11894. X    if(n > F_NAMELEN) {
  11895. X    n = F_NAMELEN;
  11896. X    }
  11897. X    (void)strncpy(mh.m_name, macname, n);
  11898. X    (void)strncpy(mh.m_type, "APPL", 4);
  11899. X    (void)strncpy(mh.m_author, "????", 4);
  11900. X    mh.m_name[n] = '\0';
  11901. X    transname(mh.m_name, trname, n);
  11902. X    define_name(trname);
  11903. X    print_header0(0);
  11904. X    print_header1(0, 0);
  11905. X    set_put(1);
  11906. X    mh.m_datalen = 0;
  11907. X    set_put(0);
  11908. X    mh.m_rsrclen = dl_fork();
  11909. X    info[I_NAMEOFF] = n;
  11910. X    (void)strncpy(info + I_NAMEOFF + 1, mh.m_name, n);
  11911. X    (void)strncpy(info + I_TYPEOFF, mh.m_type, 4);
  11912. X    (void)strncpy(info + I_AUTHOFF, mh.m_author, 4);
  11913. X    put4(info + I_DLENOFF, (unsigned long)mh.m_datalen);
  11914. X    put4(info + I_RLENOFF, (unsigned long)mh.m_rsrclen);
  11915. X    put4(info + I_CTIMOFF, (unsigned long)mh.m_createtime);
  11916. X    put4(info + I_MTIMOFF, (unsigned long)mh.m_modifytime);
  11917. X    print_header2(0);
  11918. X    end_put();
  11919. X}
  11920. X
  11921. Xstatic long dl_fork()
  11922. X{
  11923. X    register unsigned long i, v, c;
  11924. X    register unsigned long n, bytes;
  11925. X
  11926. X    n = 0;
  11927. X    bytes = 0;
  11928. X    v = 0;
  11929. X    crc = 0;
  11930. X    while((i = nchar()) != '|') {
  11931. X    if(i < '@' || i > 'O') {
  11932. X        continue;
  11933. X    }
  11934. X    v = (v << 4) | (i & 0xF);
  11935. X    if((++n & 1) == 0) {
  11936. X        put_byte((char)v);
  11937. X        crc += v;
  11938. X        v = 0;
  11939. X        bytes++;
  11940. X    }
  11941. X    }
  11942. X    c = 0;
  11943. X    for(i = 0 ; i < 8 ; i++) {
  11944. X    c = (c << 4) | (nchar() & 0xF);
  11945. X    }
  11946. X    verify_crc(bytes + crc, c);
  11947. X    return bytes;
  11948. X}
  11949. X
  11950. Xstatic int nchar()
  11951. X{
  11952. X    int i;
  11953. X
  11954. X    if((i = nextc()) == EOF) {
  11955. X    (void)fprintf(stderr, "Premature EOF\n");
  11956. X#ifdef SCAN
  11957. X    do_error("hexbin: Premature EOF");
  11958. X#endif /* SCAN */
  11959. X    exit(1);
  11960. X    }
  11961. X    return i & 0177;
  11962. X}
  11963. X
  11964. Xstatic int nextc()
  11965. X{
  11966. X    while(*icp == 0) {
  11967. X    if(readline() == 0) {
  11968. X        return EOF;
  11969. X    }
  11970. X    icp = &line[0];
  11971. X    }
  11972. X    return *icp++;
  11973. X}
  11974. X#else /* DL */
  11975. Xint dl; /* keep lint and some compilers happy */
  11976. X#endif /* DL */
  11977. X
  11978. SHAR_EOF
  11979. if test 2716 -ne "`wc -c < 'dl.c'`"
  11980. then
  11981.     echo shar: "error transmitting 'dl.c'" '(should have been 2716 characters)'
  11982. fi
  11983. fi
  11984. echo shar: "extracting 'hqx.c'" '(9295 characters)'
  11985. if test -f 'hqx.c'
  11986. then
  11987.     echo shar: "will not over-write existing file 'hqx.c'"
  11988. else
  11989. sed 's/^X//' << \SHAR_EOF > 'hqx.c'
  11990. X#include "hexbin.h"
  11991. X#ifdef HQX
  11992. X#include "globals.h"
  11993. X#include "readline.h"
  11994. X#include "crc.h"
  11995. X#include "buffer.h"
  11996. X#include "../fileio/machdr.h"
  11997. X#include "../fileio/wrfile.h"
  11998. X#include "../util/util.h"
  11999. X#include "printhdr.h"
  12000. X
  12001. Xextern void exit();
  12002. X
  12003. Xstatic void get_header();
  12004. Xstatic void oflush();
  12005. Xstatic int getq();
  12006. Xstatic long get2q();
  12007. Xstatic long get4q();
  12008. Xstatic getqbuf();
  12009. X
  12010. Xstatic char *g_macname;
  12011. X
  12012. X/* New stuff which hopes to improve the speed. */
  12013. X
  12014. X#define RUNCHAR 0x90
  12015. X
  12016. X#define DONE 0x7F
  12017. X#define SKIP 0x7E
  12018. X#define FAIL 0x7D
  12019. X
  12020. Xstatic char lookup[256] = {
  12021. X/*       ^@    ^A    ^B    ^C    ^D    ^E    ^F    ^G   */
  12022. X/* 0*/    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12023. X/*       \b    \t    \n    ^K    ^L    \r    ^N    ^O   */
  12024. X/* 1*/    FAIL, FAIL, SKIP, FAIL, FAIL, SKIP, FAIL, FAIL,
  12025. X/*       ^P    ^Q    ^R    ^S    ^T    ^U    ^V    ^W   */
  12026. X/* 2*/    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12027. X/*       ^X    ^Y    ^Z    ^[    ^\    ^]    ^^    ^_   */
  12028. X/* 3*/    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12029. X/*              !     "     #     $     %     &     '   */
  12030. X/* 4*/    FAIL, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  12031. X/*        (     )     *     +     ,     -     .     /   */
  12032. X/* 5*/    0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, FAIL, FAIL,
  12033. X/*        0     1     2     3     4     5     6     7   */
  12034. X/* 6*/    0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, FAIL,
  12035. X/*        8     9     :     ;     <     =     >     ?   */
  12036. X/* 7*/    0x14, 0x15, DONE, FAIL, FAIL, FAIL, FAIL, FAIL,
  12037. X/*        @     A     B     C     D     E     F     G   */
  12038. X/* 8*/    0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
  12039. X/*        H     I     J     K     L     M     N     O   */
  12040. X/* 9*/    0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, FAIL,
  12041. X/*        P     Q     R     S     T     U     V     W   */
  12042. X/*10*/    0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, FAIL,
  12043. X/*        X     Y     Z     [     \     ]     ^     _   */
  12044. X/*11*/    0x2C, 0x2D, 0x2E, 0x2F, FAIL, FAIL, FAIL, FAIL,
  12045. X/*        `     a     b     c     d     e     f     g   */
  12046. X/*12*/    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, FAIL,
  12047. X/*        h     i     j     k     l     m     n     o   */
  12048. X/*13*/    0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, FAIL, FAIL,
  12049. X/*        p     q     r     s     t     u     v     w   */
  12050. X/*14*/    0x3D, 0x3E, 0x3F, FAIL, FAIL, FAIL, FAIL, FAIL,
  12051. X/*        x     y     z     {     |     }     ~    ^?   */
  12052. X/*15*/    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12053. X/*16*/    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12054. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12055. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12056. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12057. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12058. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12059. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12060. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12061. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12062. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12063. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12064. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12065. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12066. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12067. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12068. X    FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
  12069. X};
  12070. X
  12071. Xstatic int stop = 0;
  12072. X
  12073. Xstatic unsigned char obuf[BUFSIZ];
  12074. Xstatic unsigned char *op = obuf;
  12075. Xstatic unsigned char *oq;
  12076. X
  12077. X#define S_HEADER    0
  12078. X#define S_DATAOPEN    1
  12079. X#define S_DATAWRITE    2
  12080. X#define S_DATAC1    3
  12081. X#define S_DATAC2    4
  12082. X#define S_RSRCOPEN    5
  12083. X#define S_RSRCWRITE    6
  12084. X#define S_RSRCC1    7
  12085. X#define S_RSRCC2    8
  12086. X#define S_EXCESS    9
  12087. X
  12088. Xstatic int ostate = S_HEADER;
  12089. X
  12090. Xstatic unsigned long calc_crc;
  12091. Xstatic unsigned long file_crc;
  12092. X
  12093. Xstatic long todo;
  12094. X
  12095. X#define output(c) { *op++ = (c); if(op >= &obuf[BUFSIZ]) oflush(); }
  12096. X
  12097. Xvoid hqx(macname)
  12098. Xchar *macname;
  12099. X{
  12100. X    int n, normlen, c;
  12101. X    register char *in, *out;
  12102. X    register int b6, b8, data, lastc = 0;
  12103. X    char state68 = 0, run = 0, linestate, first = 1;
  12104. X
  12105. X    g_macname = macname;
  12106. X
  12107. X    ostate = S_HEADER;
  12108. X    stop = 0;
  12109. X
  12110. X    while(!stop) {
  12111. X    n = strlen((char *)line);
  12112. X    while(n > 0 && line[n - 1] == ' ') {
  12113. X        n--;
  12114. X    }
  12115. X    out = line+n;
  12116. X    if(uneven_lines) {
  12117. X         goto skipcheck;
  12118. X    }
  12119. X    if(first) {
  12120. X        normlen = n;
  12121. X    }
  12122. X    /* Check line for intermediate garbage */
  12123. X    linestate = SKIP;
  12124. X    for(in = line; in < out; in++) {
  12125. X        if((linestate = lookup[*in & 0xff]) == FAIL ||
  12126. X        ((linestate == DONE) && !first)) {
  12127. X        break;
  12128. X        }
  12129. X    }
  12130. X    if(linestate != FAIL && n != normlen && linestate != DONE) {
  12131. X        c = fgetc(ifp);
  12132. X        (void)ungetc(c, ifp);
  12133. X        if(lookup[c] == DONE) {
  12134. X        linestate = DONE;
  12135. X        }
  12136. X    }
  12137. X    if(linestate == FAIL || (n != normlen && linestate != DONE)) {
  12138. X        if(verbose && n > 0) {
  12139. X        *out = 0;
  12140. X        (void)fprintf(stderr, "Skip:%s\n", line);
  12141. X        }
  12142. X        if(readline()) {
  12143. X        continue;
  12144. X        } else {
  12145. X        break;
  12146. X        }
  12147. X    }
  12148. Xskipcheck:
  12149. X    in = line;
  12150. X    do {
  12151. X        if((b6 = lookup[*in & 0xff]) >= 64) {
  12152. X        switch (b6) {
  12153. X        case DONE:
  12154. X            first = !first;
  12155. X            if(first) {
  12156. X            goto done;
  12157. X            }
  12158. X        case SKIP:
  12159. X            break;
  12160. X        default:
  12161. X            if(uneven_lines) {
  12162. X            break;
  12163. X            }
  12164. X            (void)fprintf(stderr, "bad char '%c'(%d)\n", *in, *in);
  12165. X            goto done;
  12166. X        }
  12167. X        } else {
  12168. X        /* Pack 6 bits to 8 bits */
  12169. X        switch (state68++) {
  12170. X        case 0:
  12171. X            b8 = b6<<2;
  12172. X            continue; /* No data byte */
  12173. X        case 1:
  12174. X            data = b8 | (b6>>4);
  12175. X            b8 = (b6&0xF) << 4;
  12176. X            break;
  12177. X        case 2:
  12178. X            data = b8 | (b6>>2);
  12179. X            b8 = (b6&0x3) << 6;
  12180. X            break;
  12181. X        case 3:
  12182. X            data = b8 | b6;
  12183. X            state68 = 0;
  12184. X            break;
  12185. X        }
  12186. X        if(!run) {
  12187. X            if(data == RUNCHAR) {
  12188. X            run = 1;
  12189. X            } else {
  12190. X            output(lastc = data);
  12191. X            }
  12192. X        }
  12193. X        else {
  12194. X            if(data == 0) {
  12195. X            output(lastc = RUNCHAR);
  12196. X            } else {
  12197. X            while(--data > 0) {
  12198. X                output(lastc);
  12199. X            }
  12200. X            }
  12201. X            run = 0;
  12202. X        }
  12203. X        }
  12204. X    } while(++in < out);
  12205. X    if(!stop) {
  12206. X        if(!readline()) {
  12207. X        break;
  12208. X        }
  12209. X    }
  12210. X    }
  12211. Xdone:
  12212. X    oflush();
  12213. X    if(!stop && ostate != S_EXCESS) {
  12214. X    (void)fprintf(stderr, "premature EOF\n");
  12215. X#ifdef SCAN
  12216. X    do_error("hexbin: premature EOF");
  12217. X#endif /* SCAN */
  12218. X    exit(1);
  12219. X    }
  12220. X    end_put();
  12221. X    print_header2(verbose);
  12222. X}
  12223. X
  12224. Xstatic void get_header()
  12225. X{
  12226. X    int n;
  12227. X    unsigned long calc_crc, file_crc;
  12228. X
  12229. X    crc = INITCRC;            /* compute a crc for the header */
  12230. X
  12231. X    for(n = 0; n < INFOBYTES; n++) {
  12232. X    info[n] = 0;
  12233. X    }
  12234. X    n = getq();            /* namelength */
  12235. X    n++;                /* must read trailing null also */
  12236. X    getqbuf(trname, n);        /* read name */
  12237. X    if(g_macname[0] == '\0') {
  12238. X    g_macname = trname;
  12239. X    }
  12240. X
  12241. X    n = strlen(g_macname);
  12242. X    if(n > F_NAMELEN) {
  12243. X    n = F_NAMELEN;
  12244. X    }
  12245. X    (void)strncpy(mh.m_name, g_macname, n);
  12246. X    mh.m_name[n] = '\0';
  12247. X
  12248. X    getqbuf(mh.m_type, 4);
  12249. X    getqbuf(mh.m_author, 4);
  12250. X    mh.m_flags = get2q();
  12251. X    mh.m_datalen = get4q();
  12252. X    mh.m_rsrclen = get4q();
  12253. X
  12254. X    calc_crc = crc;
  12255. X    file_crc = get2q();
  12256. X    verify_crc(calc_crc, file_crc);
  12257. X    if(listmode) {
  12258. X    (void)fprintf(stderr, "This file is in \"hqx\" format.\n");
  12259. X    }
  12260. X    transname(mh.m_name, trname, n);
  12261. X    define_name(trname);
  12262. X    print_header0(0);
  12263. X    print_header1(0, verbose);
  12264. X    info[I_NAMEOFF] = n;
  12265. X    (void)strncpy(info + I_NAMEOFF + 1, mh.m_name, n);
  12266. X    (void)strncpy(info + I_TYPEOFF, mh.m_type, 4);
  12267. X    (void)strncpy(info + I_AUTHOFF, mh.m_author, 4);
  12268. X    put2(info + I_FLAGOFF, (unsigned long)mh.m_flags);
  12269. X    put4(info + I_DLENOFF, (unsigned long)mh.m_datalen);
  12270. X    put4(info + I_RLENOFF, (unsigned long)mh.m_rsrclen);
  12271. X    put4(info + I_CTIMOFF, (unsigned long)mh.m_createtime);
  12272. X    put4(info + I_MTIMOFF, (unsigned long)mh.m_modifytime);
  12273. X}
  12274. X
  12275. Xstatic void oflush()
  12276. X{
  12277. X    int n, i;
  12278. X
  12279. X    oq = obuf;
  12280. X    while(oq < op && !stop) {
  12281. X    switch (ostate) {
  12282. X    case S_HEADER:
  12283. X        get_header();
  12284. X        ++ostate;
  12285. X        break;
  12286. X    case S_DATAOPEN:
  12287. X        set_put(1);
  12288. X        todo = mh.m_datalen;
  12289. X        crc = INITCRC;
  12290. X        ++ostate;
  12291. X        break;
  12292. X    case S_RSRCOPEN:
  12293. X        set_put(0);
  12294. X        todo = mh.m_rsrclen;
  12295. X        crc = INITCRC;
  12296. X        ++ostate;
  12297. X        break;
  12298. X    case S_DATAWRITE:
  12299. X    case S_RSRCWRITE:
  12300. X        n = op-oq;
  12301. X        if(n > todo) {
  12302. X        n = todo;
  12303. X        }
  12304. X        for(i = 0; i < n; i++) {
  12305. X        put_byte((char)(oq[i]));
  12306. X        }
  12307. X        comp_q_crc_n(oq, oq+n);
  12308. X        oq += n;
  12309. X        todo -= n;
  12310. X        if(todo <= 0) {
  12311. X        ++ostate;
  12312. X        }
  12313. X        break;
  12314. X    case S_DATAC1:
  12315. X    case S_RSRCC1:
  12316. X        calc_crc = crc;
  12317. X        file_crc = getq() << 8;
  12318. X        ++ostate;
  12319. X        break;
  12320. X    case S_DATAC2:
  12321. X    case S_RSRCC2:
  12322. X        /* Skip crc bytes */
  12323. X        file_crc |= getq();
  12324. X        verify_crc(calc_crc, file_crc);
  12325. X        ++ostate;
  12326. X        break;
  12327. X    case S_EXCESS:
  12328. X        (void)fprintf(stderr, "%d excess bytes ignored\n", op-oq);
  12329. X        oq = op;
  12330. X        break;
  12331. X    }
  12332. X    }
  12333. X    op = obuf;
  12334. X}
  12335. X
  12336. Xstatic int getq()
  12337. X{
  12338. X    int c;
  12339. X
  12340. X    if(oq >= op) {
  12341. X    (void)fprintf(stderr, "premature EOF\n");
  12342. X#ifdef SCAN
  12343. X    do_error("hexbin: premature EOF");
  12344. X#endif /* SCAN */
  12345. X    exit(1);
  12346. X    }
  12347. X    c = *oq++ & 0xff;
  12348. X    comp_q_crc((unsigned)c);
  12349. X    return c;
  12350. X}
  12351. X
  12352. X/* get2q(); q format -- read 2 bytes from input, return short */
  12353. Xstatic long get2q()
  12354. X{
  12355. X    short high = getq() << 8;
  12356. X    return high | getq();
  12357. X}
  12358. X
  12359. X/* get4q(); q format -- read 4 bytes from input, return long */
  12360. Xstatic long get4q()
  12361. X{
  12362. X    int i;
  12363. X    long value = 0;
  12364. X
  12365. X    for(i = 0; i < 4; i++) {
  12366. X    value = (value<<8) | getq();
  12367. X    }
  12368. X    return value;
  12369. X}
  12370. X
  12371. X/* getqbuf(); q format -- read n characters from input into buf */
  12372. Xstatic getqbuf(buf, n)
  12373. X    char *buf;
  12374. X    int n;
  12375. X{
  12376. X    int i;
  12377. X
  12378. X    for(i = 0; i < n; i++) {
  12379. X    *buf++ = getq();
  12380. X    }
  12381. X}
  12382. X#else /* HQX */
  12383. Xint hqx; /* keep lint and some compilers happy */
  12384. X#endif /* HQX */
  12385. X
  12386. SHAR_EOF
  12387. if test 9295 -ne "`wc -c < 'hqx.c'`"
  12388. then
  12389.     echo shar: "error transmitting 'hqx.c'" '(should have been 9295 characters)'
  12390. fi
  12391. fi
  12392. echo shar: "extracting 'printhdr.c'" '(925 characters)'
  12393. if test -f 'printhdr.c'
  12394. then
  12395.     echo shar: "will not over-write existing file 'printhdr.c'"
  12396. else
  12397. sed 's/^X//' << \SHAR_EOF > 'printhdr.c'
  12398. X#include "printhdr.h"
  12399. X#include "globals.h"
  12400. X
  12401. X/* print out header information in human-readable format */
  12402. Xvoid print_header0(skip)
  12403. Xint skip;
  12404. X{
  12405. X    if(listmode) {
  12406. X    (void)fprintf(stderr, "name=\"%s\", ", trname);
  12407. X    if(skip) {
  12408. X        (void)fprintf(stderr, "\n");
  12409. X    }
  12410. X    }
  12411. X}
  12412. X
  12413. X/* print out header information in human-readable format */
  12414. Xvoid print_header1(skip1, skip2)
  12415. Xint skip1, skip2;
  12416. X{
  12417. X    char ftype[5], fauth[5];
  12418. X
  12419. X    transname(mh.m_type, ftype, 4);
  12420. X    transname(mh.m_author, fauth, 4);
  12421. X    if(listmode) {
  12422. X    if(skip1) {
  12423. X        (void)fprintf(stderr, "\t");
  12424. X    }
  12425. X    (void)fprintf(stderr, "type=%4.4s, author=%4.4s, ", ftype, fauth);
  12426. X    if(skip2) {
  12427. X        (void)fprintf(stderr, "\n");
  12428. X    }
  12429. X    }
  12430. X}
  12431. X
  12432. X/* print out header information in human-readable format */
  12433. Xvoid print_header2(skip)
  12434. X{
  12435. X    if(listmode) {
  12436. X    if(skip) {
  12437. X        (void)fprintf(stderr, "\t");
  12438. X    }
  12439. X    (void)fprintf(stderr, "data=%ld, rsrc=%ld\n",
  12440. X        mh.m_datalen, mh.m_rsrclen);
  12441. X    }
  12442. X}
  12443. X
  12444. SHAR_EOF
  12445. if test 925 -ne "`wc -c < 'printhdr.c'`"
  12446. then
  12447.     echo shar: "error transmitting 'printhdr.c'" '(should have been 925 characters)'
  12448. fi
  12449. fi
  12450. echo shar: "extracting 'readline.h'" '(21 characters)'
  12451. if test -f 'readline.h'
  12452. then
  12453.     echo shar: "will not over-write existing file 'readline.h'"
  12454. else
  12455. sed 's/^X//' << \SHAR_EOF > 'readline.h'
  12456. Xextern char line[];
  12457. X
  12458. SHAR_EOF
  12459. if test 21 -ne "`wc -c < 'readline.h'`"
  12460. then
  12461.     echo shar: "error transmitting 'readline.h'" '(should have been 21 characters)'
  12462. fi
  12463. fi
  12464. echo shar: "extracting 'readline.c'" '(703 characters)'
  12465. if test -f 'readline.c'
  12466. then
  12467.     echo shar: "will not over-write existing file 'readline.c'"
  12468. else
  12469. sed 's/^X//' << \SHAR_EOF > 'readline.c'
  12470. X#include "globals.h"
  12471. X#include "readline.h"
  12472. X
  12473. Xchar line[1024];    /* Allow a lot! */
  12474. X
  12475. X/* Read a line.  Allow termination by CR or LF or both.  Also allow for
  12476. X   a non-terminated line at end-of-file.  Returns 1 if a line is read,
  12477. X   0 otherwise. */
  12478. Xint readline()
  12479. X{
  12480. X    int ptr = 0, c;
  12481. X
  12482. X    while(1) {
  12483. X    if(was_macbin && to_read-- <= 0) {
  12484. X        c = EOF;
  12485. X    } else {
  12486. X        c = getc(ifp);
  12487. X    }
  12488. X    if(c == EOF || c == '\n' || c == '\r' || ptr == 1023) {
  12489. X        break;
  12490. X    }
  12491. X    line[ptr++] = c;
  12492. X    }
  12493. X    line[ptr++] = 0;
  12494. X    if(c == EOF) {
  12495. X    if(ptr == 1) {
  12496. X        return 0;
  12497. X    } else {
  12498. X        return 1;
  12499. X    }
  12500. X    }
  12501. X    c = getc(ifp);
  12502. X    if(c != '\n' || c != '\r') {
  12503. X    (void)ungetc(c, ifp);
  12504. X    } else {
  12505. X    to_read--;
  12506. X    }
  12507. X    return 1;
  12508. X}
  12509. X
  12510. SHAR_EOF
  12511. if test 703 -ne "`wc -c < 'readline.c'`"
  12512. then
  12513.     echo shar: "error transmitting 'readline.c'" '(should have been 703 characters)'
  12514. fi
  12515. fi
  12516. echo shar: "extracting 'buffer.h'" '(140 characters)'
  12517. if test -f 'buffer.h'
  12518. then
  12519.     echo shar: "will not over-write existing file 'buffer.h'"
  12520. else
  12521. sed 's/^X//' << \SHAR_EOF > 'buffer.h'
  12522. Xextern char *data_fork, *rsrc_fork;
  12523. Xextern int data_size, rsrc_size;
  12524. Xextern void put_byte();
  12525. Xextern void set_put();
  12526. Xextern void end_put();
  12527. X
  12528. SHAR_EOF
  12529. if test 140 -ne "`wc -c < 'buffer.h'`"
  12530. then
  12531.     echo shar: "error transmitting 'buffer.h'" '(should have been 140 characters)'
  12532. fi
  12533. fi
  12534. echo shar: "extracting 'mu.c'" '(4891 characters)'
  12535. if test -f 'mu.c'
  12536. then
  12537.     echo shar: "will not over-write existing file 'mu.c'"
  12538. else
  12539. sed 's/^X//' << \SHAR_EOF > 'mu.c'
  12540. X#include "hexbin.h"
  12541. X#ifdef MU
  12542. X#include "globals.h"
  12543. X#include "readline.h"
  12544. X#include "../util/masks.h"
  12545. X#include "../util/util.h"
  12546. X#include "../fileio/machdr.h"
  12547. X#include "../fileio/wrfile.h"
  12548. X#include "buffer.h"
  12549. X#include "printhdr.h"
  12550. X
  12551. Xextern void exit();
  12552. X
  12553. Xstatic void do_mu_fork();
  12554. Xstatic int mu_comp_to_bin();
  12555. Xstatic int mu_convert();
  12556. X
  12557. X/* mu format -- process .mu files */
  12558. Xvoid mu(macname)
  12559. Xchar *macname;
  12560. X{
  12561. X    int n;
  12562. X
  12563. X    for(n = 0; n < INFOBYTES; n++) {
  12564. X    info[n] = 0;
  12565. X    }
  12566. X
  12567. X    /* set up name for output files */
  12568. X    if(macname[0] == '\0') {
  12569. X    n = 0;
  12570. X    while(line[n] != '"') {
  12571. X        n++;
  12572. X    }
  12573. X    macname = line + n + 1;
  12574. X    line[strlen(line) - 1] = 0;
  12575. X    }
  12576. X    n = strlen(macname);
  12577. X    if(n > F_NAMELEN) {
  12578. X    n = F_NAMELEN;
  12579. X    }
  12580. X    (void)strncpy(mh.m_name, macname, n);
  12581. X    mh.m_name[n] = '\0';
  12582. X    info[I_NAMEOFF] = n;
  12583. X    (void)strncpy(info + I_NAMEOFF + 1, mh.m_name, n);
  12584. X
  12585. X    if(listmode) {
  12586. X    (void)fprintf(stderr, "This file is in \"mu\" format.\n");
  12587. X    }
  12588. X    transname(mh.m_name, trname, n);
  12589. X    define_name(trname);
  12590. X    print_header0(0);
  12591. X    set_put(0);
  12592. X    set_put(1);
  12593. X    do_mu_fork();
  12594. X    mh.m_datalen = data_size;
  12595. X    if(!readline()) {
  12596. X    (void)fprintf(stderr, "Premature EOF\n");
  12597. X#ifdef SCAN
  12598. X    do_error("hexbin: Premature EOF");
  12599. X#endif /* SCAN */
  12600. X    exit(1);
  12601. X    }
  12602. X    if(strncmp(line, "begin ", 6)) {
  12603. X    (void)fprintf(stderr, "No UU header found.\n");
  12604. X#ifdef SCAN
  12605. X    do_error("hexbin: No UU header found");
  12606. X#endif /* SCAN */
  12607. X    exit(1);
  12608. X    }
  12609. X    if(!strncmp(line + 10, " .rsrc", 6)) {
  12610. X    set_put(0);
  12611. X    do_mu_fork();
  12612. X    mh.m_rsrclen = rsrc_size;
  12613. X    if(!readline()) {
  12614. X        (void)fprintf(stderr, "Premature EOF\n");
  12615. X#ifdef SCAN
  12616. X        do_error("hexbin: Premature EOF");
  12617. X#endif /* SCAN */
  12618. X        exit(1);
  12619. X    }
  12620. X    if(strncmp(line, "begin ", 6)) {
  12621. X        (void)fprintf(stderr, "No UU header found.\n");
  12622. X#ifdef SCAN
  12623. X        do_error("hexbin: No UU header found");
  12624. X#endif /* SCAN */
  12625. X        exit(1);
  12626. X    }
  12627. X    } else {
  12628. X    mh.m_rsrclen = 0;
  12629. X    }
  12630. X    if(strncmp(line + 10, " .finfo", 7)) {
  12631. X    (void)fprintf(stderr, "No finder info found.\n");
  12632. X#ifdef SCAN
  12633. X    do_error("hexbin: No finder info found");
  12634. X#endif /* SCAN */
  12635. X    exit(1);
  12636. X    }
  12637. X    if(!readline()) {
  12638. X    (void)fprintf(stderr, "Premature EOF\n");
  12639. X#ifdef SCAN
  12640. X    do_error("hexbin: Premature EOF");
  12641. X#endif /* SCAN */
  12642. X    exit(1);
  12643. X    }
  12644. X    (void)mu_convert(line, info + I_TYPEOFF);
  12645. X    if(!readline()) {
  12646. X    (void)fprintf(stderr, "Premature EOF\n");
  12647. X#ifdef SCAN
  12648. X    do_error("hexbin: Premature EOF");
  12649. X#endif /* SCAN */
  12650. X    exit(1);
  12651. X    }
  12652. X    if(mu_convert(line, line)) {
  12653. X    (void)fprintf(stderr, "Long finderinfo.\n");
  12654. X#ifdef SCAN
  12655. X    do_error("hexbin: Long finderinfo");
  12656. X#endif /* SCAN */
  12657. X    exit(1);
  12658. X    }
  12659. X    if(!readline()) {
  12660. X    (void)fprintf(stderr, "Premature EOF\n");
  12661. X#ifdef SCAN
  12662. X    do_error("hexbin: Premature EOF");
  12663. X#endif /* SCAN */
  12664. X    exit(1);
  12665. X    }
  12666. X    if(strncmp(line, "end", 3)) {
  12667. X    (void)fprintf(stderr, "\"end\" line missing.\n");
  12668. X#ifdef SCAN
  12669. X    do_error("hexbin: \"end\" line missing");
  12670. X#endif /* SCAN */
  12671. X    exit(1);
  12672. X    }
  12673. X
  12674. X    (void)strncpy(mh.m_type, info + I_TYPEOFF, 4);
  12675. X    (void)strncpy(mh.m_author, info + I_AUTHOFF, 4);
  12676. X    print_header1(0, 0);
  12677. X    put4(info + I_DLENOFF, (unsigned long)mh.m_datalen);
  12678. X    put4(info + I_RLENOFF, (unsigned long)mh.m_rsrclen);
  12679. X    put4(info + I_CTIMOFF, (unsigned long)mh.m_createtime);
  12680. X    put4(info + I_MTIMOFF, (unsigned long)mh.m_modifytime);
  12681. X    print_header2(0);
  12682. X    end_put();
  12683. X}
  12684. X
  12685. Xstatic void do_mu_fork()
  12686. X{
  12687. X    long newbytes;
  12688. X
  12689. X    while(readline()) {
  12690. X    if(line[0] == 0) {
  12691. X        continue;
  12692. X    }
  12693. X    newbytes = mu_comp_to_bin();
  12694. X    if(newbytes != 0) {
  12695. X        continue;
  12696. X    }
  12697. X    if(!readline()) {
  12698. X        (void)fprintf(stderr, "Premature EOF\n");
  12699. X#ifdef SCAN
  12700. X        do_error("hexbin: Premature EOF");
  12701. X#endif /* SCAN */
  12702. X        exit(1);
  12703. X    }
  12704. X    if(strncmp(line, "end", 3)) {
  12705. X        (void)fprintf(stderr, "\"end\" line missing.\n");
  12706. X#ifdef SCAN
  12707. X        do_error("hexbin: \"end\" line missing");
  12708. X#endif /* SCAN */
  12709. X        exit(1);
  12710. X    }
  12711. X    return;
  12712. X    }
  12713. X    (void)fprintf(stderr, "Premature EOF\n");
  12714. X#ifdef SCAN
  12715. X    do_error("hexbin: Premature EOF");
  12716. X#endif /* SCAN */
  12717. X    exit(1);
  12718. X    /*NOTREACHED*/
  12719. X}
  12720. X
  12721. Xstatic int mu_comp_to_bin()
  12722. X{
  12723. X    char obuf[BUFSIZ];
  12724. X    int outcount, n;
  12725. X
  12726. X    outcount = mu_convert(line, obuf);
  12727. X    for(n = 0; n < outcount; n++) {
  12728. X    put_byte(obuf[n]);
  12729. X    }
  12730. X    return outcount;
  12731. X}
  12732. X
  12733. X#define SIXB(c) (((c)-0x20) & 0x3f)
  12734. X
  12735. Xstatic int mu_convert(ibuf, obuf)
  12736. Xchar *ibuf, *obuf;
  12737. X{
  12738. X    register char *ip = ibuf;
  12739. X    register char *op = obuf;
  12740. X    register int n, outcount;
  12741. X    int numread, incount;
  12742. X
  12743. X    numread = strlen(ip);
  12744. X    outcount = SIXB(ip[0]);
  12745. X    incount = ((outcount / 3) + 1) * 4;
  12746. X    for(n = numread; n < incount; n++) {  /* restore lost spaces */
  12747. X    ip[n] = ' ';
  12748. X    }
  12749. X    ip++;
  12750. X
  12751. X    n = 0;
  12752. X    while(n <= outcount) {
  12753. X    *op++ = SIXB(ip[0]) << 2 | SIXB(ip[1]) >> 4;
  12754. X    *op++ = SIXB(ip[1]) << 4 | SIXB(ip[2]) >> 2;
  12755. X    *op++ = SIXB(ip[2]) << 6 | SIXB(ip[3]);
  12756. X    ip += 4;
  12757. X    n += 3;
  12758. X    }
  12759. X    return outcount;
  12760. X}
  12761. X#else /* MU */
  12762. Xint mu; /* keep lint and some compilers happy */
  12763. X#endif /* MU */
  12764. X
  12765. SHAR_EOF
  12766. if test 4891 -ne "`wc -c < 'mu.c'`"
  12767. then
  12768.     echo shar: "error transmitting 'mu.c'" '(should have been 4891 characters)'
  12769. fi
  12770. fi
  12771. echo shar: "extracting 'printhdr.h'" '(88 characters)'
  12772. if test -f 'printhdr.h'
  12773. then
  12774.     echo shar: "will not over-write existing file 'printhdr.h'"
  12775. else
  12776. sed 's/^X//' << \SHAR_EOF > 'printhdr.h'
  12777. Xextern void print_header0();
  12778. Xextern void print_header1();
  12779. Xextern void print_header2();
  12780. X
  12781. SHAR_EOF
  12782. if test 88 -ne "`wc -c < 'printhdr.h'`"
  12783. then
  12784.     echo shar: "error transmitting 'printhdr.h'" '(should have been 88 characters)'
  12785. fi
  12786. fi
  12787. echo shar: "extracting 'buffer.c'" '(1460 characters)'
  12788. if test -f 'buffer.c'
  12789. then
  12790.     echo shar: "will not over-write existing file 'buffer.c'"
  12791. else
  12792. sed 's/^X//' << \SHAR_EOF > 'buffer.c'
  12793. X#include "globals.h"
  12794. X#include "../util/util.h"
  12795. X#include "buffer.h"
  12796. X#include "../fileio/wrfile.h"
  12797. X
  12798. Xextern char *malloc();
  12799. Xextern char *realloc();
  12800. Xextern void exit();
  12801. X
  12802. Xchar *data_fork, *rsrc_fork;
  12803. Xint data_size, rsrc_size;
  12804. Xstatic int max_data_size, max_rsrc_size;
  12805. Xstatic int do_data;
  12806. X
  12807. Xvoid put_byte(c)
  12808. Xchar c;
  12809. X{
  12810. X    if(do_data) {
  12811. X    if(data_size >= max_data_size) {
  12812. X        if(max_data_size == 0) {
  12813. X        data_fork = malloc(1024);
  12814. X        } else {
  12815. X        data_fork = realloc(data_fork, (unsigned)max_data_size + 1024);
  12816. X        }
  12817. X        max_data_size += 1024;
  12818. X        if(data_fork == NULL) {
  12819. X        (void)fprintf(stderr, "Insufficient memory.\n");
  12820. X        exit(1);
  12821. X        }
  12822. X    }
  12823. X    data_fork[data_size++] = c;
  12824. X    } else {
  12825. X    if(rsrc_size >= max_rsrc_size) {
  12826. X        if(max_rsrc_size == 0) {
  12827. X        rsrc_fork = malloc(1024);
  12828. X        } else {
  12829. X        rsrc_fork = realloc(rsrc_fork, (unsigned)max_rsrc_size + 1024);
  12830. X        }
  12831. X        max_rsrc_size += 1024;
  12832. X        if(rsrc_fork == NULL) {
  12833. X        (void)fprintf(stderr, "Insufficient memory.\n");
  12834. X        exit(1);
  12835. X        }
  12836. X    }
  12837. X    rsrc_fork[rsrc_size++] = c;
  12838. X    }
  12839. X}
  12840. X
  12841. Xvoid set_put(data)
  12842. Xint data;
  12843. X{
  12844. X    do_data = data;
  12845. X    if(do_data) {
  12846. X    data_size = 0;
  12847. X    } else {
  12848. X    rsrc_size = 0;
  12849. X    }
  12850. X}
  12851. X
  12852. Xvoid end_put()
  12853. X{
  12854. X    if(info_only) {
  12855. X    return;
  12856. X    }
  12857. X    start_info(info, (unsigned long)rsrc_size, (unsigned long)data_size);
  12858. X    if(data_size != 0) {
  12859. X    start_data();
  12860. X    copy(out_ptr, data_fork, data_size);
  12861. X    }
  12862. X    if(rsrc_size != 0) {
  12863. X    start_rsrc();
  12864. X    copy(out_ptr, rsrc_fork, rsrc_size);
  12865. X    }
  12866. X    end_file();
  12867. X}
  12868. X
  12869. SHAR_EOF
  12870. if test 1460 -ne "`wc -c < 'buffer.c'`"
  12871. then
  12872.     echo shar: "error transmitting 'buffer.c'" '(should have been 1460 characters)'
  12873. fi
  12874. fi
  12875. echo shar: "extracting 'hexbin.h'" '(264 characters)'
  12876. if test -f 'hexbin.h'
  12877. then
  12878.     echo shar: "will not over-write existing file 'hexbin.h'"
  12879. else
  12880. sed 's/^X//' << \SHAR_EOF > 'hexbin.h'
  12881. X#define    DL    /* recognize dl format */
  12882. X#define    HECX    /* recognize hex and hcx formats */
  12883. X#define    HQX    /* recognize hqx format */
  12884. X#define    MU    /* recognize mu format */
  12885. X
  12886. X#define    form_dl        0
  12887. X#define    form_hecx    1
  12888. X#define    form_hqx    2
  12889. X#define    form_mu        3
  12890. X#define    form_none    (-1)
  12891. X
  12892. SHAR_EOF
  12893. if test 264 -ne "`wc -c < 'hexbin.h'`"
  12894. then
  12895.     echo shar: "error transmitting 'hexbin.h'" '(should have been 264 characters)'
  12896. fi
  12897. fi
  12898. echo shar: "extracting 'hecx.c'" '(5468 characters)'
  12899. if test -f 'hecx.c'
  12900. then
  12901.     echo shar: "will not over-write existing file 'hecx.c'"
  12902. else
  12903. sed 's/^X//' << \SHAR_EOF > 'hecx.c'
  12904. X#include "hexbin.h"
  12905. X#ifdef HECX
  12906. X#include "globals.h"
  12907. X#include "crc.h"
  12908. X#include "readline.h"
  12909. X#include "../util/masks.h"
  12910. X#include "../util/util.h"
  12911. X#include "../fileio/machdr.h"
  12912. X#include "../fileio/wrfile.h"
  12913. X#include "buffer.h"
  12914. X#include "printhdr.h"
  12915. X
  12916. Xextern void exit();
  12917. X
  12918. Xstatic void do_o_forks();
  12919. Xstatic long make_file();
  12920. Xstatic void comp_c_crc();
  12921. Xstatic void comp_e_crc();
  12922. Xstatic int comp_to_bin();
  12923. Xstatic int hex_to_bin();
  12924. Xstatic int hexit();
  12925. X
  12926. Xstatic int compressed;
  12927. X
  12928. X/* old format -- process .hex and .hcx files */
  12929. Xvoid hecx(macname, filename)
  12930. Xchar *macname, *filename;
  12931. X{
  12932. X    int n;
  12933. X
  12934. X    for(n = 0; n < INFOBYTES; n++) {
  12935. X    info[n] = 0;
  12936. X    }
  12937. X    compressed = 0;
  12938. X    /* set up name for output files */
  12939. X    if(macname[0] == '\0') {
  12940. X    /* strip directories */
  12941. X    macname = search_last(filename, '/');
  12942. X    if(macname == NULL) {
  12943. X        macname = filename;
  12944. X    } else {
  12945. X        macname++;
  12946. X    }
  12947. X
  12948. X    /* strip extension */
  12949. X    n = strlen(macname);
  12950. X    if(n > 4) {
  12951. X        n -= 4;
  12952. X        if(!strncmp(macname + n, ".hex", 4) ||
  12953. X           !strncmp(macname + n, ".hcx", 4)) {
  12954. X        macname[n] = '\0';
  12955. X        }
  12956. X    }
  12957. X    }
  12958. X    n = strlen(macname);
  12959. X    if(n > F_NAMELEN) {
  12960. X    n = F_NAMELEN;
  12961. X    }
  12962. X    (void)strncpy(mh.m_name, macname, n);
  12963. X    mh.m_name[n] = '\0';
  12964. X
  12965. X    /* "#TYPEAUTH$flag"  line already read */
  12966. X    n = strlen(line);
  12967. X    if(n >= 6 && line[0] == '#' && line[n-5] == '$') {
  12968. X    if(n >= 10) {
  12969. X        (void)strncpy(mh.m_type, &line[1], 4);
  12970. X    }
  12971. X    if(n >= 14) {
  12972. X        (void)strncpy(mh.m_author, &line[5], 4);
  12973. X    }
  12974. X    (void)sscanf(&line[n-4], "%4hx", &mh.m_flags);
  12975. X    }
  12976. X    transname(mh.m_name, trname, n);
  12977. X    define_name(trname);
  12978. X    do_o_forks();
  12979. X    if(listmode) {
  12980. X    if(!compressed) {
  12981. X        (void)fprintf(stderr, "This file is in \"hex\" format.\n");
  12982. X    } else {
  12983. X        (void)fprintf(stderr, "This file is in \"hcx\" format.\n");
  12984. X    }
  12985. X    }
  12986. X    print_header0(0);
  12987. X    print_header1(0, 0);
  12988. X    info[I_NAMEOFF] = n;
  12989. X    (void)strncpy(info + I_NAMEOFF + 1, mh.m_name, n);
  12990. X    (void)strncpy(info + I_TYPEOFF, mh.m_type, 4);
  12991. X    (void)strncpy(info + I_AUTHOFF, mh.m_author, 4);
  12992. X    put2(info + I_FLAGOFF, (unsigned long)mh.m_flags);
  12993. X    put4(info + I_DLENOFF, (unsigned long)mh.m_datalen);
  12994. X    put4(info + I_RLENOFF, (unsigned long)mh.m_rsrclen);
  12995. X    put4(info + I_CTIMOFF, (unsigned long)mh.m_createtime);
  12996. X    put4(info + I_MTIMOFF, (unsigned long)mh.m_modifytime);
  12997. X    print_header2(0);
  12998. X    end_put();
  12999. X}
  13000. X
  13001. Xstatic void do_o_forks()
  13002. X{
  13003. X    int forks = 0, found_crc = 0;
  13004. X    unsigned long calc_crc, file_crc;
  13005. X
  13006. X    crc = 0;    /* calculate a crc for both forks */
  13007. X
  13008. X    set_put(0);
  13009. X    set_put(1);
  13010. X    while(!found_crc && readline()) {
  13011. X    if(line[0] == 0) {
  13012. X        continue;
  13013. X    }
  13014. X    if(forks == 0 && strncmp(line, "***COMPRESSED", 13) == 0) {
  13015. X        compressed++;
  13016. X        continue;
  13017. X    }
  13018. X    if(strncmp(line, "***DATA", 7) == 0) {
  13019. X        set_put(1);
  13020. X        mh.m_datalen = make_file(compressed);
  13021. X        forks++;
  13022. X        continue;
  13023. X    }
  13024. X    if(strncmp(line, "***RESOURCE", 11) == 0) {
  13025. X        set_put(0);
  13026. X        mh.m_rsrclen = make_file(compressed);
  13027. X        forks++;
  13028. X        continue;
  13029. X    }
  13030. X    if(compressed && strncmp(line, "***CRC:", 7) == 0) {
  13031. X        found_crc++;
  13032. X        calc_crc = crc;
  13033. X        (void)sscanf(&line[7], "%lx", &file_crc);
  13034. X        break;
  13035. X    }
  13036. X    if(!compressed && strncmp(line, "***CHECKSUM:", 12) == 0) {
  13037. X        found_crc++;
  13038. X        calc_crc = crc & BYTEMASK;
  13039. X        (void)sscanf(&line[12], "%lx", &file_crc);
  13040. X        file_crc &= BYTEMASK;
  13041. X        break;
  13042. X    }
  13043. X    }
  13044. X
  13045. X    if(found_crc) {
  13046. X    verify_crc(calc_crc, file_crc);
  13047. X    } else {
  13048. X    (void)fprintf(stderr, "missing CRC\n");
  13049. X#ifdef SCAN
  13050. X    do_error("hexbin: missing CRC");
  13051. X#endif /* SCAN */
  13052. X    exit(1);
  13053. X    }
  13054. X}
  13055. X
  13056. Xstatic long make_file(compressed)
  13057. Xint compressed;
  13058. X{
  13059. X    register long nbytes = 0L;
  13060. X
  13061. X    while(readline()) {
  13062. X    if(line[0] == 0) {
  13063. X        continue;
  13064. X    }
  13065. X    if(strncmp(line, "***END", 6) == 0) {
  13066. X        break;
  13067. X    }
  13068. X    if(compressed) {
  13069. X        nbytes += comp_to_bin();
  13070. X    } else {
  13071. X        nbytes += hex_to_bin();
  13072. X    }
  13073. X    }
  13074. X    return nbytes;
  13075. X}
  13076. X
  13077. Xstatic void comp_c_crc(c)
  13078. Xunsigned char c;
  13079. X{
  13080. X    crc = (crc + c) & WORDMASK;
  13081. X    crc = ((crc << 3) & WORDMASK) | (crc >> 13);
  13082. X}
  13083. X
  13084. Xstatic void comp_e_crc(c)
  13085. Xunsigned char c;
  13086. X{
  13087. X    crc += c;
  13088. X}
  13089. X
  13090. X#define SIXB(c) (((c)-0x20) & 0x3f)
  13091. X
  13092. Xstatic int comp_to_bin()
  13093. X{
  13094. X    char obuf[BUFSIZ];
  13095. X    register char *ip = line;
  13096. X    register char *op = obuf;
  13097. X    register int n, outcount;
  13098. X    int numread, incount;
  13099. X
  13100. X    numread = strlen(line);
  13101. X    outcount = (SIXB(ip[0]) << 2) | (SIXB(ip[1]) >> 4);
  13102. X    incount = ((outcount / 3) + 1) * 4;
  13103. X    for(n = numread; n < incount; n++) {  /* restore lost spaces */
  13104. X    line[n] = ' ';
  13105. X    }
  13106. X
  13107. X    n = 0;
  13108. X    while(n <= outcount) {
  13109. X    *op++ = SIXB(ip[0]) << 2 | SIXB(ip[1]) >> 4;
  13110. X    *op++ = SIXB(ip[1]) << 4 | SIXB(ip[2]) >> 2;
  13111. X    *op++ = SIXB(ip[2]) << 6 | SIXB(ip[3]);
  13112. X    ip += 4;
  13113. X    n += 3;
  13114. X    }
  13115. X
  13116. X    for(n = 1; n <= outcount; n++) {
  13117. X    comp_c_crc((unsigned)obuf[n]);
  13118. X    put_byte(obuf[n]);
  13119. X    }
  13120. X    return outcount;
  13121. X}
  13122. X
  13123. Xstatic int hex_to_bin()
  13124. X{
  13125. X    register char *ip = line;
  13126. X    register int n, outcount;
  13127. X    int c;
  13128. X
  13129. X    n = strlen(line);
  13130. X    outcount = n / 2;
  13131. X    for(n = 0; n < outcount; n++) {
  13132. X    c = hexit((int)*ip++);
  13133. X    comp_e_crc((unsigned)(c = (c << 4) | hexit((int)*ip++)));
  13134. X    put_byte((char)c);
  13135. X    }
  13136. X    return outcount;
  13137. X}
  13138. X
  13139. Xstatic int hexit(c)
  13140. Xint c;
  13141. X{
  13142. X    if('0' <= c && c <= '9') {
  13143. X    return c - '0';
  13144. X    }
  13145. X    if('A' <= c && c <= 'F') {
  13146. X    return c - 'A' + 10;
  13147. X    }
  13148. X
  13149. X    (void)fprintf(stderr, "illegal hex digit: %c", c);
  13150. X#ifdef SCAN
  13151. X    do_error("hexbin: illegal hex digit");
  13152. X#endif /* SCAN */
  13153. X    exit(1);
  13154. X    /* NOTREACHED */
  13155. X}
  13156. X#else /* HECX */
  13157. Xint hecx; /* keep lint and some compilers happy */
  13158. X#endif /* HECX */
  13159. X
  13160. SHAR_EOF
  13161. if test 5468 -ne "`wc -c < 'hecx.c'`"
  13162. then
  13163.     echo shar: "error transmitting 'hecx.c'" '(should have been 5468 characters)'
  13164. fi
  13165. fi
  13166. echo shar: "done with directory 'hexbin'"
  13167. cd ..
  13168. if test ! -d 'util'
  13169. then
  13170.     echo shar: "creating directory 'util'"
  13171.     mkdir 'util'
  13172. fi
  13173. echo shar: "entering directory 'util'"
  13174. cd 'util'
  13175. echo shar: "extracting 'makefile'" '(291 characters)'
  13176. if test -f 'makefile'
  13177. then
  13178.     echo shar: "will not over-write existing file 'makefile'"
  13179. else
  13180. sed 's/^X//' << \SHAR_EOF > 'makefile'
  13181. XCFLAGS=    -O $(CF)
  13182. X
  13183. Xall:    util.o transname.o backtrans.o
  13184. X    touch all
  13185. X
  13186. Xutil.o:    util.c
  13187. X
  13188. Xtransname.o:    transname.c
  13189. X
  13190. Xbacktrans.o:    backtrans.c
  13191. X
  13192. Xclean:
  13193. X    -rm -f util.o
  13194. X    -rm -f transname.o
  13195. X    -rm -f backtrans.o
  13196. X    -rm -f all
  13197. X
  13198. Xutil.o:    ../fileio/fileglob.h
  13199. Xutil.o:    masks.h
  13200. Xutil.o:    util.h
  13201. Xbacktrans.o:    masks.h
  13202. X
  13203. SHAR_EOF
  13204. if test 291 -ne "`wc -c < 'makefile'`"
  13205. then
  13206.     echo shar: "error transmitting 'makefile'" '(should have been 291 characters)'
  13207. fi
  13208. fi
  13209. echo shar: "extracting 'util.h'" '(465 characters)'
  13210. if test -f 'util.h'
  13211. then
  13212.     echo shar: "will not over-write existing file 'util.h'"
  13213. else
  13214. sed 's/^X//' << \SHAR_EOF > 'util.h'
  13215. Xtypedef struct real_time {
  13216. X    int year;
  13217. X    int month;
  13218. X    int day;
  13219. X    int hours;
  13220. X    int minutes;
  13221. X    int seconds;
  13222. X} real_time;
  13223. X
  13224. Xextern unsigned long get4();
  13225. Xextern unsigned long get4i();
  13226. Xextern unsigned long get2();
  13227. Xextern unsigned long get2i();
  13228. Xextern unsigned char getb();
  13229. Xextern void copy();
  13230. Xextern int do_query();
  13231. Xextern void put4();
  13232. Xextern void put2();
  13233. Xextern void do_indent();
  13234. Xextern real_time set_time();
  13235. Xextern unsigned long tomactime();
  13236. Xextern real_time frommactime();
  13237. X
  13238. SHAR_EOF
  13239. if test 465 -ne "`wc -c < 'util.h'`"
  13240. then
  13241.     echo shar: "error transmitting 'util.h'" '(should have been 465 characters)'
  13242. fi
  13243. fi
  13244. echo shar: "extracting 'util.c'" '(3583 characters)'
  13245. if test -f 'util.c'
  13246. then
  13247.     echo shar: "will not over-write existing file 'util.c'"
  13248. else
  13249. sed 's/^X//' << \SHAR_EOF > 'util.c'
  13250. X#include <stdio.h>
  13251. X#include "../fileio/fileglob.h"
  13252. X#include "masks.h"
  13253. X#include "util.h"
  13254. X
  13255. Xextern void exit();
  13256. X
  13257. X#define MACTIMOFFS    1904
  13258. X
  13259. Xstatic int mlength[] = {0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337};
  13260. X
  13261. Xunsigned long get4(bp)
  13262. Xchar *bp;
  13263. X{
  13264. X    register int i;
  13265. X    long value = 0;
  13266. X
  13267. X    for(i = 0; i < 4; i++) {
  13268. X    value <<= 8;
  13269. X    value |= (*bp & BYTEMASK);
  13270. X    bp++;
  13271. X    }
  13272. X    return value;
  13273. X}
  13274. X
  13275. X/* For if integers are stored wrong-endian. */
  13276. Xunsigned long get4i(bp)
  13277. Xchar *bp;
  13278. X{
  13279. X    register int i;
  13280. X    long value = 0;
  13281. X
  13282. X    bp += 3;
  13283. X    for(i = 0; i < 4; i++) {
  13284. X        value <<= 8;
  13285. X        value |= (*bp & BYTEMASK);
  13286. X        bp--;
  13287. X    }
  13288. X    return value;
  13289. X}
  13290. X
  13291. Xunsigned long get2(bp)
  13292. Xchar *bp;
  13293. X{
  13294. X    register int i;
  13295. X    int value = 0;
  13296. X
  13297. X    for(i = 0; i < 2; i++) {
  13298. X    value <<= 8;
  13299. X    value |= (*bp & BYTEMASK);
  13300. X    bp++;
  13301. X    }
  13302. X    return value;
  13303. X}
  13304. X
  13305. X/* For if integers are stored wrong-endian. */
  13306. Xunsigned long get2i(bp)
  13307. Xchar *bp;
  13308. X{
  13309. X    register int i;
  13310. X    long value = 0;
  13311. X
  13312. X    bp += 1;
  13313. X    for(i = 0; i < 2; i++) {
  13314. X        value <<= 8;
  13315. X        value |= (*bp & BYTEMASK);
  13316. X        bp--;
  13317. X    }
  13318. X    return value;
  13319. X}
  13320. X
  13321. Xunsigned char getb(fp)
  13322. XFILE *fp;
  13323. X{
  13324. X    int c;
  13325. X
  13326. X    bytes_read += 1;
  13327. X    c = getc(fp);
  13328. X    if(c == EOF) {
  13329. X    (void)fprintf(stderr, "\nPremature EOF\n");
  13330. X    exit(1);
  13331. X    }
  13332. X    return c & BYTEMASK;
  13333. X}
  13334. X
  13335. Xvoid copy(d, s, n)
  13336. Xchar *d, *s;
  13337. Xint n;
  13338. X{
  13339. X    while(--n >= 0) {
  13340. X    *d++ = *s++;
  13341. X    }
  13342. X}
  13343. X
  13344. Xint do_query()
  13345. X{
  13346. X    char *tp, temp[10];
  13347. X
  13348. X    (void)fprintf(stderr, "? ");
  13349. X    (void) fflush(stdout);
  13350. X    (void) read(2, temp, sizeof(temp));
  13351. X    temp[sizeof(temp) - 1] = 0;
  13352. X    tp = temp;
  13353. X    while(*tp != 0) {
  13354. X    if(*tp == 'y' || *tp == 'Y') {
  13355. X        return 1;
  13356. X    } else {
  13357. X        tp++;
  13358. X    }
  13359. X    }
  13360. X    return 0;
  13361. X}
  13362. X
  13363. Xvoid put4(dest, value)
  13364. Xchar *dest;
  13365. Xunsigned long value;
  13366. X{
  13367. X    *dest++ = (value >> 24) & BYTEMASK;
  13368. X    *dest++ = (value >> 16) & BYTEMASK;
  13369. X    *dest++ = (value >> 8) & BYTEMASK;
  13370. X    *dest++ = value & BYTEMASK;
  13371. X}
  13372. X
  13373. Xvoid put2(dest, value)
  13374. Xchar *dest;
  13375. Xunsigned long value;
  13376. X{
  13377. X    *dest++ = (value >> 8) & BYTEMASK;
  13378. X    *dest++ = value & BYTEMASK;
  13379. X}
  13380. X
  13381. Xvoid do_indent(indent)
  13382. Xint indent;
  13383. X{
  13384. X    int i;
  13385. X
  13386. X    for(i = 0; i < indent; i++) {
  13387. X    (void)fputc(' ', stderr);
  13388. X    }
  13389. X}
  13390. X
  13391. Xreal_time set_time(year, month, day, hours, minutes, seconds)
  13392. Xint year, month, day, hours, minutes, seconds;
  13393. X{
  13394. X    real_time toset;
  13395. X
  13396. X    toset.year = year;
  13397. X    toset.month = month;
  13398. X    toset.day = day;
  13399. X    toset.hours = hours;
  13400. X    toset.minutes = minutes;
  13401. X    toset.seconds = seconds;
  13402. X    return toset;
  13403. X}
  13404. X
  13405. Xunsigned long tomactime(time)
  13406. Xreal_time time;
  13407. X{
  13408. X    long accum;
  13409. X    int year;
  13410. X
  13411. X    accum = time.month - 3;
  13412. X    year = time.year;
  13413. X    if(accum < 0) {
  13414. X    accum += 12;
  13415. X    year--;
  13416. X    }
  13417. X    accum = time.day + mlength[accum] + 59;
  13418. X    accum += (year - MACTIMOFFS) * 365 + year / 4 - MACTIMOFFS / 4;
  13419. X    accum = ((accum * 24 + time.hours) * 60 + time.minutes) * 60 + time.seconds;
  13420. X    return (unsigned)accum;
  13421. X}
  13422. X
  13423. Xreal_time frommactime(accum)
  13424. Xunsigned long accum;
  13425. X{
  13426. Xlong tmp1, tmp2;
  13427. Xreal_time time;
  13428. X
  13429. X    time.seconds = tmp1 = accum % 60;
  13430. X    accum /= 60;
  13431. X    time.minutes = tmp1 = accum % 60;
  13432. X    accum /= 60;
  13433. X    time.hours = tmp1 = accum % 24;
  13434. X    accum /= 24;
  13435. X    tmp1 = (long)accum - 60;
  13436. X    tmp2 = tmp1 % 1461;
  13437. X    if(tmp2 < 0) {
  13438. X    tmp2 += 1461;
  13439. X    }
  13440. X    tmp1 = (tmp1 - tmp2) / 1461;
  13441. X    time.year = tmp1 * 4;
  13442. X    tmp1 = tmp2 / 365;
  13443. X    if(tmp1 > 3) {
  13444. X    tmp1 = 3;
  13445. X    }
  13446. X    time.year += tmp1 + MACTIMOFFS;
  13447. X    tmp2 -= tmp1 * 365;
  13448. X    tmp1 = 12;
  13449. X    while(mlength[--tmp1] > tmp2);
  13450. X    time.day = tmp2 + 1 - mlength[tmp1];
  13451. X    time.month = tmp1 + 3;
  13452. X    if(tmp1 > 9) {
  13453. X    time.month = tmp1 - 9;
  13454. X    time.year++;
  13455. X    }
  13456. X    return time;
  13457. X}
  13458. X
  13459. SHAR_EOF
  13460. if test 3583 -ne "`wc -c < 'util.c'`"
  13461. then
  13462.     echo shar: "error transmitting 'util.c'" '(should have been 3583 characters)'
  13463. fi
  13464. fi
  13465. echo shar: "extracting 'masks.h'" '(87 characters)'
  13466. if test -f 'masks.h'
  13467. then
  13468.     echo shar: "will not over-write existing file 'masks.h'"
  13469. else
  13470. sed 's/^X//' << \SHAR_EOF > 'masks.h'
  13471. X#define    NIBBLEMASK    0x0000000f
  13472. X#define    BYTEMASK    0x000000ff
  13473. X#define    WORDMASK    0x0000ffff
  13474. X
  13475. SHAR_EOF
  13476. if test 87 -ne "`wc -c < 'masks.h'`"
  13477. then
  13478.     echo shar: "error transmitting 'masks.h'" '(should have been 87 characters)'
  13479. fi
  13480. fi
  13481. echo shar: "extracting 'transname.c'" '(4465 characters)'
  13482. if test -f 'transname.c'
  13483. then
  13484.     echo shar: "will not over-write existing file 'transname.c'"
  13485. else
  13486. sed 's/^X//' << \SHAR_EOF > 'transname.c'
  13487. X#include <sys/types.h>
  13488. X#include <sys/dir.h>
  13489. X
  13490. Xchar *strncpy();
  13491. X
  13492. X#ifdef MAXNAMLEN    /* 4.2 BSD */
  13493. X#define FNAMELEN MAXNAMLEN
  13494. X#else
  13495. X#define FNAMELEN DIRSIZ
  13496. X#endif
  13497. X
  13498. X/* Create a Unix file name based on the Mac filename.  First off we have
  13499. X * possible problems with filename sizes (Sys V) and also with allowable
  13500. X * characters.  Mac filename characters can be anything from 1 to 254 (I
  13501. X * think 0 and 255 are not allowed) with colon disallowed.  Unix filenames
  13502. X * have also a lot of freedom, but cannot contain 0 or '/'.  Also on Unix
  13503. X * non-printable are a trouble (you will never see the filename correctly;
  13504. X * and it may even lock your terminal with some versions of Unix).
  13505. X * So first off non-printable characters are mapped to underscore.
  13506. X * Although there are Unix systems that allow the high order bit set in
  13507. X * a filename character in all programs, nearly all implementations do not
  13508. X * allow that, so also characters in the range 0200-0377 are mapped to
  13509. X * underscore (except as noted below).  Some people would also like to
  13510. X * remap characters that are special to some shells (open brackets,
  13511. X * asterisks, exclamation point (csh), etc.)  I did elect not to do so
  13512. X * because there is no end.  (The previous code disallowed a lot, but not
  13513. X * the braces that are special to some shells, obviously he was a C-shell user!)
  13514. X * Characters in the range 0200-0377 are in part accented letters
  13515. X * (the Swedes, Norwegians and Danes would not agree, but who listens to
  13516. X * them!); those are mapped to the unaccented version.  All other characters
  13517. X * in this range are mapped to underscore.  Note: this is based on the
  13518. X * Geneva font!
  13519. X * This stuff is now largely table driven.
  13520. X * One day I may modify this so that an environment variable may be used
  13521. X * to define mappings. */
  13522. X
  13523. Xstatic char char_mapping[] = {
  13524. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13525. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13526. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13527. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13528. X     '_',  '!',  '"',  '#',  '$',  '%',  '&', '\'',
  13529. X     '(',  ')',  '*',  '+',  ',',  '-',  '.',  '_',
  13530. X     '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
  13531. X     '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
  13532. X     '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
  13533. X     'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
  13534. X     'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
  13535. X     'X',  'Y',  'Z',  '[', '\\',  ']',  '^',  '_',
  13536. X     '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
  13537. X     'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
  13538. X     'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
  13539. X     'x',  'y',  'z',  '{',  '|',  '}',  '~',  '_',
  13540. X#ifndef LATIN1
  13541. X     'A',  'A',  'C',  'E',  'N',  'O',  'U',  'a',
  13542. X     'a',  'a',  'a',  'a',  'a',  'c',  'e',  'e',
  13543. X     'e',  'e',  'i',  'i',  'i',  'i',  'n',  'o',
  13544. X     'o',  'o',  'o',  'o',  'u',  'u',  'u',  'u',
  13545. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13546. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  'O',
  13547. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13548. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  'o',
  13549. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13550. X     '_',  '_',  '_',  'A',  'A',  'O',  '_',  '_',
  13551. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13552. X     'y',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13553. X#else /* LATIN1 */
  13554. X    0304, 0305, 0307, 0311, 0321, 0326, 0334, 0341,
  13555. X    0340, 0342, 0344, 0343, 0345, 0347, 0351, 0350,
  13556. X    0352, 0353, 0355, 0354, 0356, 0357, 0361, 0363,
  13557. X    0362, 0364, 0366, 0365, 0372, 0371, 0373, 0374,
  13558. X     '_', 0260, 0242, 0243, 0247, 0267, 0266, 0337,
  13559. X    0256, 0251,  '_', 0264, 0250,  '_', 0306, 0330,
  13560. X     '_', 0261,  '_',  '_', 0245,  '_',  '_',  '_',
  13561. X     '_',  '_',  '_',  '_',  '_',  '_', 0346, 0370,
  13562. X    0277, 0241, 0254,  '_',  '_',  '_',  '_', 0253,
  13563. X    0273,  '_',  '_', 0300, 0303, 0325,  '_',  '_',
  13564. X     '_',  '_',  '_',  '_',  '_',  '_', 0367, 0244,
  13565. X    0377,  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13566. X#endif /* LATIN1 */
  13567. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13568. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13569. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13570. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_'};
  13571. X
  13572. Xvoid transname(name, namebuf, n)
  13573. Xchar *name, *namebuf;
  13574. Xint n;
  13575. X{
  13576. X    char *np;
  13577. X
  13578. X    /* make sure host file name doesn't get truncated beyond recognition */
  13579. X    if (n > FNAMELEN - 2) {
  13580. X    n = FNAMELEN - 2;
  13581. X    }
  13582. X    (void)strncpy(namebuf, name, n);
  13583. X    namebuf[n] = '\0';
  13584. X
  13585. X    /* now: translate name */
  13586. X    for (np = namebuf; *np; np++){
  13587. X    *np = char_mapping[*np & 0xff];
  13588. X    }
  13589. X#ifdef NODOT
  13590. X    if(*namebuf == '.') {
  13591. X    *namebuf = '_';
  13592. X    }
  13593. X#endif /* NODOT */
  13594. X}
  13595. X
  13596. SHAR_EOF
  13597. if test 4465 -ne "`wc -c < 'transname.c'`"
  13598. then
  13599.     echo shar: "error transmitting 'transname.c'" '(should have been 4465 characters)'
  13600. fi
  13601. fi
  13602. echo shar: "extracting 'backtrans.c'" '(3367 characters)'
  13603. if test -f 'backtrans.c'
  13604. then
  13605.     echo shar: "will not over-write existing file 'backtrans.c'"
  13606. else
  13607. sed 's/^X//' << \SHAR_EOF > 'backtrans.c'
  13608. X#include "masks.h"
  13609. X
  13610. X/* Map a command line given name to a Mac name.  If LATIN1 is not defined
  13611. X   the translation is direct, except that \ is handled special.  \\ is
  13612. X   translated to \, \ddd (three digits) is translated to the octal code.
  13613. X   If LATIN1 is defined, special care has been taken with the 8 bit chars
  13614. X   to get a proper mapping, if possible.  Note: colon is translated to _. */
  13615. Xstatic char char_mapping[] = {
  13616. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13617. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13618. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13619. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13620. X     ' ',  '!',  '"',  '#',  '$',  '%',  '&', '\'',
  13621. X     '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
  13622. X     '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
  13623. X     '8',  '9',  '_',  ';',  '<',  '=',  '>',  '?',
  13624. X     '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
  13625. X     'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
  13626. X     'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
  13627. X     'X',  'Y',  'Z',  '[', '\\',  ']',  '^',  '_',
  13628. X     '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
  13629. X     'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
  13630. X     'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
  13631. X     'x',  'y',  'z',  '{',  '|',  '}',  '~', 0177,
  13632. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13633. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13634. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13635. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13636. X#ifndef LATIN1
  13637. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13638. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13639. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13640. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13641. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13642. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13643. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13644. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13645. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13646. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13647. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13648. X     '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_'};
  13649. X#else /* LATIN1 */
  13650. X     '_', 0301, 0242, 0243, 0327, 0265,  '_', 0244,
  13651. X    0254, 0251,  '_', 0307, 0302,  '_', 0250,  '_',
  13652. X    0241, 0261,  '_',  '_', 0253,  '_', 0246, 0245,
  13653. X     '_',  '_',  '_', 0310,  '_',  '_',  '_', 0300,
  13654. X    0313, 0207, 0211, 0313, 0200, 0201, 0256, 0202,
  13655. X    0217, 0203, 0220, 0221, 0223, 0314, 0224, 0225,
  13656. X     '_', 0204, 0230, 0227, 0231, 0233, 0205,  '_',
  13657. X    0257, 0235, 0234, 0236, 0206,  '_',  '_', 0247,
  13658. X    0210, 0207, 0211, 0213, 0212, 0214, 0276, 0215,
  13659. X    0217, 0216, 0220, 0221, 0223, 0222, 0224, 0225,
  13660. X     '_', 0226, 0230, 0227, 0231, 0233, 0232, 0326,
  13661. X    0277, 0235, 0234, 0236, 0237,  '_',  '_', 0330};
  13662. X#endif /* LATIN1 */
  13663. X
  13664. Xvoid backtrans(macname, name)
  13665. Xchar *macname, *name;
  13666. X{
  13667. X    char *in, *out;
  13668. X    int c, count = 0;
  13669. X
  13670. X    out = macname;
  13671. X    for (in = name; *in; in++){
  13672. X    if(count == 31) {
  13673. X        break;
  13674. X    }
  13675. X    if(*in != '\\') {
  13676. X        *out++ = char_mapping[*in & BYTEMASK];
  13677. X        count++;
  13678. X        continue;
  13679. X    }
  13680. X    in++;
  13681. X    if(*in == 0) {
  13682. X        break;;
  13683. X    }
  13684. X    if(*in < '0' || *in > '9') {
  13685. X        *out++ = char_mapping[*in & BYTEMASK];
  13686. X        count++;
  13687. X        continue;
  13688. X    }
  13689. X    c = *in - '0';
  13690. X    in++;
  13691. X    if(*in < '0' || *in > '9') {
  13692. X        *out++ = c;
  13693. X        count++;
  13694. X        in--;
  13695. X        continue;
  13696. X    }
  13697. X    c = (c << 3) + *in - '0';
  13698. X    in++;
  13699. X    if(*in < '0' || *in > '9') {
  13700. X        *out++ = c;
  13701. X        count++;
  13702. X        in--;
  13703. X        continue;
  13704. X    }
  13705. X    c = (c << 3) + *in - '0';
  13706. X    *out++ = c;
  13707. X    count++;
  13708. X    }
  13709. X    *out++ = 0;
  13710. X}
  13711. X
  13712. SHAR_EOF
  13713. if test 3367 -ne "`wc -c < 'backtrans.c'`"
  13714. then
  13715.     echo shar: "error transmitting 'backtrans.c'" '(should have been 3367 characters)'
  13716. fi
  13717. fi
  13718. echo shar: "extracting 'patchlevel.h'" '(61 characters)'
  13719. if test -f 'patchlevel.h'
  13720. then
  13721.     echo shar: "will not over-write existing file 'patchlevel.h'"
  13722. else
  13723. sed 's/^X//' << \SHAR_EOF > 'patchlevel.h'
  13724. X#define    VERSION        "2.0b1 (26-APR-1992)"
  13725. X#define PATCHLEVEL    0
  13726. X
  13727. SHAR_EOF
  13728. if test 61 -ne "`wc -c < 'patchlevel.h'`"
  13729. then
  13730.     echo shar: "error transmitting 'patchlevel.h'" '(should have been 61 characters)'
  13731. fi
  13732. fi
  13733. echo shar: "extracting 'curtime.h'" '(240 characters)'
  13734. if test -f 'curtime.h'
  13735. then
  13736.     echo shar: "will not over-write existing file 'curtime.h'"
  13737. else
  13738. sed 's/^X//' << \SHAR_EOF > 'curtime.h'
  13739. X#ifdef TYPES_H
  13740. X#include <sys/types.h>
  13741. X#endif /* TYPES_H */
  13742. X
  13743. X#ifdef BSD
  13744. X#include <sys/time.h>
  13745. Xextern time_t time();
  13746. X#else /* BSD */
  13747. X#include <time.h>
  13748. X#endif /* BSD */
  13749. X
  13750. X/* Mac time of 00:00:00 GMT, Jan 1, 1970 */
  13751. X#define TIMEDIFF 0x7c25b080
  13752. X
  13753. SHAR_EOF
  13754. if test 240 -ne "`wc -c < 'curtime.h'`"
  13755. then
  13756.     echo shar: "error transmitting 'curtime.h'" '(should have been 240 characters)'
  13757. fi
  13758. fi
  13759. echo shar: "done with directory 'util'"
  13760. cd ..
  13761. if test ! -d 'mixed'
  13762. then
  13763.     echo shar: "creating directory 'mixed'"
  13764.     mkdir 'mixed'
  13765. fi
  13766. echo shar: "entering directory 'mixed'"
  13767. cd 'mixed'
  13768. echo shar: "extracting 'macsave.c'" '(1929 characters)'
  13769. if test -f 'macsave.c'
  13770. then
  13771.     echo shar: "will not over-write existing file 'macsave.c'"
  13772. else
  13773. sed 's/^X//' << \SHAR_EOF > 'macsave.c'
  13774. X#include "globals.h"
  13775. X#include "../util/patchlevel.h"
  13776. X#include "../fileio/wrfile.h"
  13777. X#include "../fileio/wrfileopt.h"
  13778. X#include "../util/util.h"
  13779. X
  13780. X#define LOCALOPT    "ilqVH"
  13781. X
  13782. Xextern char *strcat();
  13783. Xvoid macbinary();
  13784. X
  13785. Xstatic void usage();
  13786. X
  13787. Xstatic char options[128];
  13788. X
  13789. Xint main(argc, argv)
  13790. Xint argc;
  13791. Xchar *argv[];
  13792. X{
  13793. X    int c;
  13794. X    extern int optind;
  13795. X    extern char *optarg;
  13796. X    int errflg;
  13797. X
  13798. X    set_wrfileopt(0);
  13799. X    set_s_wrfileopt(1);
  13800. X    (void)strcat(options, get_wrfileopt());
  13801. X    (void)strcat(options, LOCALOPT);
  13802. X    errflg = 0;
  13803. X
  13804. X    while((c = getopt(argc, argv, options)) != EOF) {
  13805. X    if(!wrfileopt((char)c)) {
  13806. X        switch(c) {
  13807. X        case 'l':
  13808. X        list++;
  13809. X        break;
  13810. X        case 'q':
  13811. X        query++;
  13812. X        break;
  13813. X        case 'i':
  13814. X        info_only++;
  13815. X        break;
  13816. X        case '?':
  13817. X        errflg++;
  13818. X        break;
  13819. X        case 'H':
  13820. X        give_wrfileopt();
  13821. X        (void)fprintf(stderr, "Macsave specific options:\n");
  13822. X        (void)fprintf(stderr,
  13823. X            "-i:\tgive information only, do not save\n");
  13824. X        (void)fprintf(stderr, "-l:\tgive listing\n");
  13825. X        (void)fprintf(stderr,
  13826. X            "-q:\tquery for every file/folder before saving\n");
  13827. X        (void)fprintf(stderr,
  13828. X            "-V:\tgive information about this version\n");
  13829. X        (void)fprintf(stderr, "-H:\tthis message\n");
  13830. X        (void)fprintf(stderr, "Default is silent saving\n");
  13831. X        exit(0);
  13832. X        case 'V':
  13833. X        (void)fprintf(stderr, "Version %s, ", VERSION);
  13834. X        (void)fprintf(stderr, "patchlevel %d", PATCHLEVEL);
  13835. X        (void)fprintf(stderr, "%s.\n", get_mina());
  13836. X        exit(0);
  13837. X        }
  13838. X    }
  13839. X    }
  13840. X    if(errflg || optind != argc) {
  13841. X    usage();
  13842. X    exit(1);
  13843. X    }
  13844. X
  13845. X    infp = stdin;
  13846. X
  13847. X    if(info_only || query) {
  13848. X    list++;
  13849. X    }
  13850. X    c = getc(infp);
  13851. X    (void)ungetc(c, infp);
  13852. X    switch(c) {
  13853. X    case 0:
  13854. X    macbinary();
  13855. X    break;
  13856. X    default:
  13857. X    (void)fprintf(stderr, "Input is not MacBinary\n");
  13858. X    exit(1);
  13859. X    }
  13860. X    exit(0);
  13861. X    /* NOTREACHED */
  13862. X}
  13863. X
  13864. Xstatic void usage()
  13865. X{
  13866. X    (void)fprintf(stderr, "Usage: macsave [-%s]\n", options);
  13867. X    (void)fprintf(stderr, "Use \"macsave -H\" for help.\n");
  13868. X}
  13869. X
  13870. SHAR_EOF
  13871. if test 1929 -ne "`wc -c < 'macsave.c'`"
  13872. then
  13873.     echo shar: "error transmitting 'macsave.c'" '(should have been 1929 characters)'
  13874. fi
  13875. fi
  13876. echo shar: "extracting 'macstream.c'" '(4060 characters)'
  13877. if test -f 'macstream.c'
  13878. then
  13879.     echo shar: "will not over-write existing file 'macstream.c'"
  13880. else
  13881. sed 's/^X//' << \SHAR_EOF > 'macstream.c'
  13882. X#include <stdio.h>
  13883. X#include "../fileio/machdr.h"
  13884. X#include "../fileio/rdfile.h"
  13885. X#include "../fileio/rdfileopt.h"
  13886. X#include "../util/patchlevel.h"
  13887. X
  13888. Xextern char *malloc();
  13889. Xextern char *realloc();
  13890. Xextern char *strcat();
  13891. Xextern void exit();
  13892. Xextern void transname();
  13893. Xextern void do_indent();
  13894. X
  13895. X#define LOCALOPT    "ilqVH"
  13896. X
  13897. Xstatic void usage();
  13898. X
  13899. Xstatic char options[128];
  13900. Xstatic char *dir_stack;
  13901. Xstatic int dir_ptr = -64;
  13902. Xstatic int dir_max;
  13903. X
  13904. Xint main(argc, argv)
  13905. Xint argc;
  13906. Xchar **argv;
  13907. X{
  13908. X    int c, i, j, n;
  13909. X    extern int optind;
  13910. X    extern char *optarg;
  13911. X    int errflg;
  13912. X    char text[32], ftype[5], fauth[5];
  13913. X    int dir_skip = 0, write_it, query = 0, list = 0, info_only = 0;
  13914. X    int indent = 0;
  13915. X
  13916. X    (void)strcat(options, get_rdfileopt());
  13917. X    (void)strcat(options, LOCALOPT);
  13918. X    errflg = 0;
  13919. X
  13920. X    while((c = getopt(argc, argv, options)) != EOF) {
  13921. X    if(!rdfileopt((char)c)) {
  13922. X        switch(c) {
  13923. X        case 'l':
  13924. X        list++;
  13925. X        break;
  13926. X        case 'q':
  13927. X        query++;
  13928. X        break;
  13929. X        case 'i':
  13930. X        info_only++;
  13931. X        break;
  13932. X        case '?':
  13933. X        errflg++;
  13934. X        break;
  13935. X        case 'H':
  13936. X        give_rdfileopt();
  13937. X        (void)fprintf(stderr, "Macstream specific options:\n");
  13938. X        (void)fprintf(stderr,
  13939. X            "-i:\tgive information only, do not write\n");
  13940. X        (void)fprintf(stderr, "-l:\tgive listing\n");
  13941. X        (void)fprintf(stderr,
  13942. X            "-q:\tquery for every file/folder before writing\n");
  13943. X        (void)fprintf(stderr,
  13944. X            "-V:\tgive information about this version\n");
  13945. X        (void)fprintf(stderr, "-H:\tthis message\n");
  13946. X        (void)fprintf(stderr, "Default is silent writing\n");
  13947. X        exit(0);
  13948. X        case 'V':
  13949. X        (void)fprintf(stderr, "Version %s, ", VERSION);
  13950. X        (void)fprintf(stderr, "patchlevel %d", PATCHLEVEL);
  13951. X        (void)fprintf(stderr, "%s.\n", get_minb());
  13952. X        exit(0);
  13953. X        }
  13954. X    }
  13955. X    }
  13956. X    if(errflg || optind == argc) {
  13957. X    usage();
  13958. X    exit(1);
  13959. X    }
  13960. X
  13961. X    if(info_only || query) {
  13962. X    list++;
  13963. X    }
  13964. X
  13965. X    setup(argc - optind, argv + optind);
  13966. X    while((i = nextfile()) != ISATEND) {
  13967. X    if(dir_skip) {
  13968. X        if(i == ISDIR) {
  13969. X        dir_skip++;
  13970. X        } else if(i == ENDDIR) {
  13971. X        dir_skip--;
  13972. X        }
  13973. X        continue;
  13974. X    }
  13975. X
  13976. X    write_it = 1;
  13977. X    n = file_info[I_NAMEOFF] & 0x7f;
  13978. X    transname(file_info + I_NAMEOFF + 1, text, n);
  13979. X    if(i == ISFILE) {
  13980. X        transname(file_info + I_TYPEOFF, ftype, 4);
  13981. X        transname(file_info + I_AUTHOFF, fauth, 4);
  13982. X    }
  13983. X    if(list) {
  13984. X        if(i == ISFILE) {
  13985. X        do_indent(indent);
  13986. X        (void)fprintf(stderr,
  13987. X            "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  13988. X            text, ftype, fauth, (long)data_size, (long)rsrc_size);
  13989. X        } else if(i == ISDIR) {
  13990. X        do_indent(indent);
  13991. X        dir_ptr += 64;
  13992. X        if(dir_ptr == dir_max) {
  13993. X            if(dir_max == 0) {
  13994. X            dir_stack = malloc(64);
  13995. X            } else {
  13996. X            dir_stack = realloc(dir_stack, (unsigned)dir_max + 64);
  13997. X            }
  13998. X            dir_max += 64;
  13999. X            if(dir_stack == NULL) {
  14000. X            (void)fprintf(stderr, "Insufficient memory\n");
  14001. X            exit(1);
  14002. X            }
  14003. X        }
  14004. X        for(j = 0; j <= n; j++) {
  14005. X            dir_stack[dir_ptr + j] = text[j];
  14006. X        }
  14007. X        (void)fprintf(stderr, "folder=\"%s\"", text);
  14008. X        indent++;
  14009. X        } else {
  14010. X        indent--;
  14011. X        do_indent(indent);
  14012. X        (void)fprintf(stderr, "leaving folder \"%s\"",
  14013. X            dir_stack + dir_ptr);
  14014. X        dir_ptr -= 64;
  14015. X        }
  14016. X        if(info_only) {
  14017. X        write_it = 0;
  14018. X        }
  14019. X        if(query) {
  14020. X        if(i != ENDDIR) {
  14021. X            write_it = do_query();
  14022. X        } else {
  14023. X            (void)fputc('\n', stderr);
  14024. X        }
  14025. X        if(!write_it && i == ISDIR) {
  14026. X            dir_skip = 1;
  14027. X            indent--;
  14028. X            dir_ptr -= 64;
  14029. X        }
  14030. X        } else {
  14031. X        (void)fputc('\n', stderr);
  14032. X        }
  14033. X    }
  14034. X
  14035. X    if(write_it) {
  14036. X        (void)fwrite(file_info, 1, 128, stdout);
  14037. X        if(i == ISFILE) {
  14038. X        if(data_size != 0) {
  14039. X            (void)fwrite(data_fork, 1, data_size, stdout);
  14040. X            i = (((data_size + 127) >> 7) << 7) - data_size;
  14041. X            while(i-- > 0) {
  14042. X            (void)fputc(0, stdout);
  14043. X            }
  14044. X        }
  14045. X        if(rsrc_size != 0) {
  14046. X            (void)fwrite(rsrc_fork, 1, rsrc_size, stdout);
  14047. X            i = (((rsrc_size + 127) >> 7) << 7) - rsrc_size;
  14048. X            while(i-- > 0) {
  14049. X            (void)fputc(0, stdout);
  14050. X            }
  14051. X        }
  14052. X        }
  14053. X    }
  14054. X    }
  14055. X    exit(0);
  14056. X    /* NOTREACHED */
  14057. X}
  14058. X
  14059. Xstatic void usage()
  14060. X{
  14061. X    (void)fprintf(stderr, "Usage: macstream [-%s] files\n", options);
  14062. X    (void)fprintf(stderr, "Use \"macstream -H\" for help.\n");
  14063. X}
  14064. X
  14065. SHAR_EOF
  14066. if test 4060 -ne "`wc -c < 'macstream.c'`"
  14067. then
  14068.     echo shar: "error transmitting 'macstream.c'" '(should have been 4060 characters)'
  14069. fi
  14070. fi
  14071. echo shar: "extracting 'all'" '(0 character)'
  14072. if test -f 'all'
  14073. then
  14074.     echo shar: "will not over-write existing file 'all'"
  14075. else
  14076. sed 's/^X//' << \SHAR_EOF > 'all'
  14077. SHAR_EOF
  14078. if test 0 -ne "`wc -c < 'all'`"
  14079. then
  14080.     echo shar: "error transmitting 'all'" '(should have been 0 characters)'
  14081. fi
  14082. fi
  14083. echo shar: "extracting 'dir.c'" '(1357 characters)'
  14084. if test -f 'dir.c'
  14085. then
  14086.     echo shar: "will not over-write existing file 'dir.c'"
  14087. else
  14088. sed 's/^X//' << \SHAR_EOF > 'dir.c'
  14089. X#include "globals.h"
  14090. X#include "../fileio/machdr.h"
  14091. X#include "../fileio/wrfile.h"
  14092. X#include "../util/util.h"
  14093. X#include "../util/masks.h"
  14094. X
  14095. Xextern char *malloc();
  14096. Xextern char *realloc();
  14097. X
  14098. Xstatic char *dir_stack;
  14099. Xstatic int dir_ptr = -64;
  14100. Xstatic int dir_max;
  14101. X
  14102. Xvoid dir(hdr)
  14103. Xchar *hdr;
  14104. X{
  14105. Xint doit;
  14106. X
  14107. X    if((hdr[I_NAMEOFF] & BYTEMASK) == 0x80) {
  14108. X    if(dir_skip) {
  14109. X        dir_skip--;
  14110. X        return;
  14111. X    }
  14112. X    indent--;
  14113. X    if(list) {
  14114. X        do_indent(indent);
  14115. X        (void)fprintf(stderr, "leaving folder \"%s\"\n",
  14116. X            dir_stack + dir_ptr);
  14117. X    }
  14118. X    if(!info_only) {
  14119. X        enddir();
  14120. X    }
  14121. X    dir_ptr -= 64;
  14122. X    return;
  14123. X    }
  14124. X    if(dir_skip) {
  14125. X    dir_skip++;
  14126. X    return;
  14127. X    }
  14128. X    dir_ptr += 64;
  14129. X    if(dir_ptr == dir_max) {
  14130. X    if(dir_max == 0) {
  14131. X        dir_stack = malloc(64);
  14132. X    } else {
  14133. X        dir_stack = realloc(dir_stack, (unsigned)dir_max + 64);
  14134. X    }
  14135. X    dir_max += 64;
  14136. X    if(dir_stack == NULL) {
  14137. X        (void)fprintf(stderr, "Insufficient memory\n");
  14138. X        exit(1);
  14139. X    }
  14140. X    }
  14141. X    transname(hdr + I_NAMEOFF + 1, dir_stack + dir_ptr,
  14142. X          (int)(hdr[I_NAMEOFF] & 0x7f));
  14143. X    doit = 1;
  14144. X    if(list) {
  14145. X    do_indent(indent);
  14146. X    (void)fprintf(stderr, "folder=\"%s\"", dir_stack + dir_ptr);
  14147. X    if(query) {
  14148. X        doit = do_query();
  14149. X    } else {
  14150. X        (void)fputc('\n', stderr);
  14151. X    }
  14152. X    }
  14153. X    if(!doit) {
  14154. X    dir_ptr -= 64;
  14155. X    dir_skip = 1;
  14156. X    return;
  14157. X    }
  14158. X    if(!info_only) {
  14159. X    do_mkdir(dir_stack + dir_ptr, hdr);
  14160. X    }
  14161. X    indent++;
  14162. X}
  14163. X
  14164. SHAR_EOF
  14165. if test 1357 -ne "`wc -c < 'dir.c'`"
  14166. then
  14167.     echo shar: "error transmitting 'dir.c'" '(should have been 1357 characters)'
  14168. fi
  14169. fi
  14170. echo shar: "extracting 'globals.c'" '(250 characters)'
  14171. if test -f 'globals.c'
  14172. then
  14173.     echo shar: "will not over-write existing file 'globals.c'"
  14174. else
  14175. sed 's/^X//' << \SHAR_EOF > 'globals.c'
  14176. X#include "globals.h"
  14177. X#include "../fileio/machdr.h"
  14178. X
  14179. Xchar info[INFOBYTES];
  14180. Xchar text[F_NAMELEN+1];
  14181. X
  14182. Xint list, info_only, query, write_it, indent, dir_skip;
  14183. XFILE *infp;
  14184. Xint in_data_size = -1;
  14185. Xint in_rsrc_size = -1;
  14186. Xint in_ds, in_rs, ds_skip, rs_skip;
  14187. X
  14188. SHAR_EOF
  14189. if test 250 -ne "`wc -c < 'globals.c'`"
  14190. then
  14191.     echo shar: "error transmitting 'globals.c'" '(should have been 250 characters)'
  14192. fi
  14193. fi
  14194. echo shar: "extracting 'globals.h'" '(262 characters)'
  14195. if test -f 'globals.h'
  14196. then
  14197.     echo shar: "will not over-write existing file 'globals.h'"
  14198. else
  14199. sed 's/^X//' << \SHAR_EOF > 'globals.h'
  14200. X#include <stdio.h>
  14201. X
  14202. Xextern void exit();
  14203. Xextern void transname();
  14204. X
  14205. Xextern char info[];
  14206. Xextern char text[];
  14207. X
  14208. Xextern int list, info_only, query, write_it, indent, dir_skip;
  14209. Xextern FILE *infp;
  14210. X
  14211. Xextern int in_data_size, in_rsrc_size, in_ds, in_rs, ds_skip, rs_skip;
  14212. X
  14213. SHAR_EOF
  14214. if test 262 -ne "`wc -c < 'globals.h'`"
  14215. then
  14216.     echo shar: "error transmitting 'globals.h'" '(should have been 262 characters)'
  14217. fi
  14218. fi
  14219. echo shar: "extracting 'macbinary.c'" '(2696 characters)'
  14220. if test -f 'macbinary.c'
  14221. then
  14222.     echo shar: "will not over-write existing file 'macbinary.c'"
  14223. else
  14224. sed 's/^X//' << \SHAR_EOF > 'macbinary.c'
  14225. X#include "globals.h"
  14226. X#include "../fileio/machdr.h"
  14227. X#include "../fileio/kind.h"
  14228. X#include "../util/util.h"
  14229. X
  14230. Xextern void dir();
  14231. Xextern void mcb();
  14232. Xextern void do_indent();
  14233. X
  14234. Xstatic void skip_file();
  14235. X#ifdef SCAN
  14236. Xstatic void get_idf();
  14237. X#endif /* SCAN */
  14238. X
  14239. Xvoid macbinary()
  14240. X{
  14241. X    char header[INFOBYTES];
  14242. X    int c;
  14243. X
  14244. X    while(1) {
  14245. X    if((c = fgetc(infp)) == EOF) {
  14246. X        break;
  14247. X    }
  14248. X    (void)ungetc(c, infp);
  14249. X    if(fread(header, 1, INFOBYTES, infp) != INFOBYTES) {
  14250. X        (void)fprintf(stderr, "Can't read MacBinary header.\n");
  14251. X        exit(1);
  14252. X    }
  14253. X    if(header[I_NAMEOFF] & 0x80) {
  14254. X        dir(header);
  14255. X        continue;
  14256. X    }
  14257. X    in_data_size = get4(header + I_DLENOFF);
  14258. X    in_rsrc_size = get4(header + I_RLENOFF);
  14259. X    in_ds = (((in_data_size + 127) >> 7) << 7);
  14260. X    in_rs = (((in_rsrc_size + 127) >> 7) << 7);
  14261. X    ds_skip = in_ds - in_data_size;
  14262. X    rs_skip = in_rs - in_rsrc_size;
  14263. X    if(dir_skip != 0) {
  14264. X        skip_file(in_ds + in_rs);
  14265. X        continue;
  14266. X    }
  14267. X#ifdef SCAN
  14268. X    if(header[I_NAMEOFF] == 0) {
  14269. X        get_idf((int)header[I_NAMEOFF + 1]);
  14270. X        skip_file(ds_skip + in_rs);
  14271. X        continue;
  14272. X    }
  14273. X#endif /* SCAN */
  14274. X    if(header[0] == 0 /* MORE CHECKS HERE! */) {
  14275. X        mcb(header, (unsigned long)in_rsrc_size,
  14276. X            (unsigned long)in_data_size, in_ds + in_rs);
  14277. X        continue;
  14278. X    } else {
  14279. X        (void)fprintf(stderr, "Unrecognized header.\n");
  14280. X        exit(1);
  14281. X    }
  14282. X    }
  14283. X}
  14284. X
  14285. Xstatic void skip_file(skip)
  14286. X    int skip;
  14287. X{
  14288. X    char buff[1024];
  14289. X    int n;
  14290. X
  14291. X    while(skip > 0) {
  14292. X    n = (skip < 1024 ? skip : 1024);
  14293. X    if(fread(buff, 1, n, infp) != n) {
  14294. X        (void)fprintf(stderr, "Incomplete file.\n");
  14295. X        exit(1);
  14296. X    }
  14297. X    skip -= n;
  14298. X    }
  14299. X}
  14300. X
  14301. X#ifdef SCAN
  14302. Xstatic void get_idf(kind)
  14303. X    int kind;
  14304. X{
  14305. X    char filename[1024], filename1[255];
  14306. X
  14307. X    if(fread(filename, 1, in_data_size, infp) != in_data_size) {
  14308. X    (void)fprintf(stderr, "Incomplete file.\n");
  14309. X    exit(1);
  14310. X    }
  14311. X    filename[in_data_size] = 0;
  14312. X    if(list) {
  14313. X    do_indent(indent);
  14314. X    switch(kind) {
  14315. X    case UNIX_NAME:
  14316. X        (void)fprintf(stderr, "Unix filename: \"%s\"\n", filename);
  14317. X        break;
  14318. X    case PACK_NAME:
  14319. X        transname(filename, filename1, in_data_size);
  14320. X        (void)fprintf(stderr, "Packed filename: \"%s\"\n", filename1);
  14321. X        break;
  14322. X    case ARCH_NAME:
  14323. X        transname(filename, filename1, in_data_size);
  14324. X        (void)fprintf(stderr, "Archive name: \"%s\"\n", filename1);
  14325. X        break;
  14326. X    case UNKNOWN:
  14327. X        (void)fprintf(stderr, "Unknown method detected\n");
  14328. X        break;
  14329. X    case ERROR:
  14330. X        (void)fprintf(stderr, "Error detected\n");
  14331. X        break;
  14332. X    case PROTECTED:
  14333. X        (void)fprintf(stderr, "Protected file detected\n");
  14334. X        break;
  14335. X    case COPY:
  14336. X        (void)fprintf(stderr, "Copied file found\n");
  14337. X        break;
  14338. X    default:
  14339. X        (void)fprintf(stderr, "Do not understand this identification\n");
  14340. X        exit(1);
  14341. X    }
  14342. X    }
  14343. X}
  14344. X#endif /* SCAN */
  14345. X
  14346. SHAR_EOF
  14347. if test 2696 -ne "`wc -c < 'macbinary.c'`"
  14348. then
  14349.     echo shar: "error transmitting 'macbinary.c'" '(should have been 2696 characters)'
  14350. fi
  14351. fi
  14352. echo shar: "extracting 'makefile'" '(1946 characters)'
  14353. if test -f 'makefile'
  14354. then
  14355.     echo shar: "will not over-write existing file 'makefile'"
  14356. else
  14357. sed 's/^X//' << \SHAR_EOF > 'makefile'
  14358. XCFLAGS = -O $(CF)
  14359. X
  14360. XSRCS1 =    macsave.c \
  14361. X    globals.c \
  14362. X    macbinary.c \
  14363. X    dir.c \
  14364. X    mcb.c
  14365. X
  14366. XSRCS2 =    macstream.c
  14367. X
  14368. XOBJS1 =    macsave.o \
  14369. X    globals.o \
  14370. X    macbinary.o \
  14371. X    dir.o \
  14372. X    mcb.o
  14373. X
  14374. XOBJS2 =    macstream.o
  14375. X
  14376. XTNAME =    ../util/transname
  14377. XUNAME =    ../util/util
  14378. XONAME =    ../fileio/wrfile
  14379. XINAME = ../fileio/rdfile
  14380. XGNAME =    ../fileio/fileglob
  14381. XXOBJS1=    $(TNAME).o $(UNAME).o $(ONAME).o $(GNAME).o
  14382. XXSRCS1=    $(TNAME).c $(UNAME).c $(ONAME).c $(GNAME).c
  14383. XXOBJS2=    $(TNAME).o $(UNAME).o $(INAME).o $(GNAME).o
  14384. XXSRCS2=    $(TNAME).c $(UNAME).c $(INAME).c $(GNAME).c
  14385. XXOBJS3=    $(UNAME).o $(ONAME).o $(GNAME).o
  14386. XXSRCS3=    $(UNAME).c $(ONAME).c $(GNAME).c
  14387. X
  14388. Xall:    macsave macstream
  14389. X    touch all
  14390. X
  14391. Xmacsave:    $(OBJS1) $(XOBJS1)
  14392. X    $(CC) $(CFLAGS) -o macsave $(OBJS1) $(XOBJS1)
  14393. X
  14394. Xmacstream:    $(OBJS2) $(XOBJS2)
  14395. X    $(CC) $(CFLAGS) -o macstream $(OBJS2) $(XOBJS2)
  14396. X
  14397. X$(TNAME).o:    $(TNAME).c
  14398. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  14399. X
  14400. X$(UNAME).o:    $(UNAME).c
  14401. X    (cd ../util; make CC=$(CC) CF="$(CF)" )
  14402. X
  14403. X$(ONAME).o:    $(ONAME).c
  14404. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  14405. X
  14406. X$(INAME).o:    $(INAME).c
  14407. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  14408. X
  14409. X$(GNAME).o:    $(GNAME).c
  14410. X    (cd ../fileio; make CC=$(CC) CF="$(CF)" )
  14411. X
  14412. Xlint:
  14413. X    lint $(CF) $(LFLAGS) $(SRCS1) $(XSRCS1)
  14414. X    lint $(CF) $(LFLAGS) $(SRCS2) $(XSRCS2)
  14415. X
  14416. Xclean:
  14417. X    -rm -f *.o
  14418. X
  14419. Xclobber:clean
  14420. X    -rm -f macsave macstream
  14421. X
  14422. Xmacsave.o:    globals.h
  14423. Xmacsave.o:    ../util/patchlevel.h
  14424. Xmacsave.o:    ../fileio/wrfile.h
  14425. Xmacsave.o:    ../fileio/wrfileopt.h
  14426. Xmacsave.o:    ../util/util.h
  14427. Xglobals.o:    globals.h
  14428. Xglobals.o:    ../fileio/machdr.h
  14429. Xmacbinary.o:    globals.h
  14430. Xmacbinary.o:    ../fileio/machdr.h
  14431. Xmacbinary.o:    ../fileio/kind.h
  14432. Xmacbinary.o:    ../util/util.h
  14433. Xdir.o:    globals.h
  14434. Xdir.o:    ../fileio/machdr.h
  14435. Xdir.o:    ../fileio/wrfile.h
  14436. Xdir.o:    ../util/util.h
  14437. Xdir.o:    ../util/masks.h
  14438. Xmcb.o:    globals.h
  14439. Xmcb.o:    ../fileio/machdr.h
  14440. Xmcb.o:    ../fileio/wrfile.h
  14441. Xmcb.o:    ../util/masks.h
  14442. Xmcb.o:    ../util/util.h
  14443. Xmacstream.o:    ../fileio/machdr.h
  14444. Xmacstream.o:    ../fileio/rdfile.h
  14445. Xmacstream.o:    ../fileio/rdfileopt.h
  14446. Xmacstream.o:    ../util/patchlevel.h
  14447. X
  14448. SHAR_EOF
  14449. if test 1946 -ne "`wc -c < 'makefile'`"
  14450. then
  14451.     echo shar: "error transmitting 'makefile'" '(should have been 1946 characters)'
  14452. fi
  14453. fi
  14454. echo shar: "extracting 'mcb.c'" '(2030 characters)'
  14455. if test -f 'mcb.c'
  14456. then
  14457.     echo shar: "will not over-write existing file 'mcb.c'"
  14458. else
  14459. sed 's/^X//' << \SHAR_EOF > 'mcb.c'
  14460. X#include "globals.h"
  14461. X#include "../fileio/machdr.h"
  14462. X#include "../fileio/wrfile.h"
  14463. X#include "../util/masks.h"
  14464. X#include "../util/util.h"
  14465. X
  14466. Xstatic int mcb_read;
  14467. X
  14468. Xstatic void mcb_wrfile();
  14469. X
  14470. Xvoid mcb(hdr, rsrcLength, dataLength, toread)
  14471. Xchar *hdr;
  14472. Xunsigned long rsrcLength, dataLength;
  14473. Xint toread;
  14474. X{
  14475. X    register int i;
  14476. X    int n;
  14477. X    char ftype[5], fauth[5];
  14478. X
  14479. X    mcb_read = toread;
  14480. X    for(i = 0; i < INFOBYTES; i++) {
  14481. X    info[i] = hdr[i];
  14482. X    }
  14483. X
  14484. X    n = hdr[I_NAMEOFF] & BYTEMASK;
  14485. X    if(n > F_NAMELEN) {
  14486. X    n = F_NAMELEN;
  14487. X    }
  14488. X    info[I_NAMEOFF] = n;
  14489. X    transname(hdr + I_NAMEOFF + 1, text, n);
  14490. X    if(hdr[I_LOCKOFF] & 1) {
  14491. X    hdr[I_FLAGOFF + 1] = PROTCT_MASK;
  14492. X    hdr[I_LOCKOFF] &= ~1;
  14493. X    }
  14494. X
  14495. X    write_it = 1;
  14496. X    if(list) {
  14497. X    transname(hdr + I_TYPEOFF, ftype, 4);
  14498. X    transname(hdr + I_AUTHOFF, fauth, 4);
  14499. X    do_indent(indent);
  14500. X    (void)fprintf(stderr,
  14501. X        "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  14502. X        text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  14503. X    if(info_only) {
  14504. X        write_it = 0;
  14505. X    }
  14506. X    if(query) {
  14507. X        write_it = do_query();
  14508. X    } else {
  14509. X        (void)fputc('\n', stderr);
  14510. X    }
  14511. X    }
  14512. X
  14513. X    if(write_it) {
  14514. X    define_name(text);
  14515. X    start_info(info, rsrcLength, dataLength);
  14516. X    start_data();
  14517. X    }
  14518. X    mcb_wrfile(dataLength);
  14519. X    if(write_it) {
  14520. X    start_rsrc();
  14521. X    }
  14522. X    mcb_wrfile(rsrcLength);
  14523. X    if(write_it) {
  14524. X    end_file();
  14525. X    }
  14526. X}
  14527. X
  14528. Xstatic void mcb_wrfile(ibytes)
  14529. Xunsigned long ibytes;
  14530. X{
  14531. X    int n;
  14532. X
  14533. X    if(write_it) {
  14534. X    if(ibytes == 0) {
  14535. X        return;
  14536. X    }
  14537. X    n = fread(out_buffer, 1, (int)ibytes, infp);
  14538. X    if(n != ibytes) {
  14539. X        (void)fprintf(stderr, "Premature EOF\n");
  14540. X        exit(1);
  14541. X    }
  14542. X    mcb_read -= n;
  14543. X    n = ((n + 127) / 128) * 128 - n;
  14544. X    if(n > mcb_read) {
  14545. X        n = mcb_read;
  14546. X    }
  14547. X    mcb_read -= n;
  14548. X    while(n-- > 0) {
  14549. X        if(getc(infp) == EOF) {
  14550. X        (void)fprintf(stderr, "Premature EOF\n");
  14551. X        exit(1);
  14552. X        }
  14553. X    }
  14554. X    } else {
  14555. X    n = ((ibytes + 127) / 128) * 128;
  14556. X    if(n > mcb_read) {
  14557. X        n = mcb_read;
  14558. X    }
  14559. X    mcb_read -= n;
  14560. X    while(n-- > 0) {
  14561. X        if(getc(infp) == EOF) {
  14562. X        (void)fprintf(stderr, "Premature EOF\n");
  14563. X        exit(1);
  14564. X        }
  14565. X    }
  14566. X    }
  14567. X}
  14568. X
  14569. SHAR_EOF
  14570. if test 2030 -ne "`wc -c < 'mcb.c'`"
  14571. then
  14572.     echo shar: "error transmitting 'mcb.c'" '(should have been 2030 characters)'
  14573. fi
  14574. fi
  14575. echo shar: "done with directory 'mixed'"
  14576. cd ..
  14577. if test ! -d 'man'
  14578. then
  14579.     echo shar: "creating directory 'man'"
  14580.     mkdir 'man'
  14581. fi
  14582. echo shar: "entering directory 'man'"
  14583. cd 'man'
  14584. echo shar: "extracting 'macunpack.1'" '(2386 characters)'
  14585. if test -f 'macunpack.1'
  14586. then
  14587.     echo shar: "will not over-write existing file 'macunpack.1'"
  14588. else
  14589. sed 's/^X//' << \SHAR_EOF > 'macunpack.1'
  14590. X.TH MACUNPACK L "July 13, 1991"
  14591. X.UC
  14592. X.SH NAME
  14593. Xmacunpack \- Macintosh file de-archiver
  14594. X.SH SYNOPSIS
  14595. X.B macunpack
  14596. X[
  14597. X.B \- options
  14598. X] [ file ]
  14599. X.br
  14600. X.SH DESCRIPTION
  14601. X.I macunpack
  14602. Xtakes the specified Macintosh MacBinary archive specified in
  14603. X.I file
  14604. X(or standard input if none is specified) and extracts the files it
  14605. Xcontains subject to the
  14606. X.I options
  14607. Xspecified.
  14608. XThe program will also accept the data fork of the archive for some kinds
  14609. Xof archive.
  14610. X.SH OPTIONS
  14611. XIn the absence of any options,
  14612. X.I macunpack
  14613. Xtakes the specified archive and silently extracts the file(s) it contains
  14614. Xinto MacBinary format, giving the output files ".bin" extensions and
  14615. Xplacing them in the current working directory.
  14616. XSubdirectories are created for embedded folders.
  14617. X.TP
  14618. X.B \-3 
  14619. XWrite files in fork format (.info, .data and .rsrc files)
  14620. X.TP
  14621. X.B \-f 
  14622. XAs -3, but empty data and rsrc files are not created
  14623. X.TP
  14624. X.B \-r
  14625. XWrite resource forks only (.rsrc files)
  14626. X.TP
  14627. X.B \-d
  14628. XWrite data forks only (.data files)
  14629. X.TP
  14630. X.B \-u
  14631. XAs -d, but the codes for CR and LF are interchanged
  14632. X.TP
  14633. X.B \-a
  14634. XWrite files in AUFS format.
  14635. XThis option is only valid if the program is compiled with AUFS support.
  14636. XThe current directory must be a valid AUFS folder.
  14637. X.TP
  14638. X.B \-s
  14639. XWrite extracted files to standard output in MacBinary format.
  14640. X.TP
  14641. X.B \-l
  14642. XList every file extracted (and every directory/folder created etc.)
  14643. X.TP
  14644. X.B \-v
  14645. XLike -l, but more verbose (Implies -l)
  14646. X.TP
  14647. X.B \-i
  14648. XDo not extract, give information only (Implies -l)
  14649. X.TP
  14650. X.B \-q
  14651. XAsk the user for every file/folder whether it should be extracted
  14652. X(implies -l)
  14653. X.TP
  14654. X.B \-V
  14655. XGives the patchlevel of the program, and other information.
  14656. XOther options are ignored and the program quits immediately.
  14657. X.TP
  14658. X.B \-H
  14659. XGive short information about the options.
  14660. XOther options are ignored and the program quits immediately.
  14661. X.SH BUGS
  14662. XAs this is a beta release, there may still be some problems.  Archives
  14663. Xthat are password protected, multi-file archives, and files archived
  14664. Xusing Stuffit Deluxe's compression methods 6 or 8 (Fixed Huffman and
  14665. XBigram compression) are not dealt with.
  14666. X.SH AUTHOR
  14667. XDik T. Winter, Amsterdam, The Netherlands (dik@cwi.nl)
  14668. X.sp 1
  14669. XParts of the code are based on codes from:
  14670. XSteve Davies,
  14671. XRahul Dhesi,
  14672. XCasper H.S. Dik,
  14673. XJim McKie,
  14674. XMark G. Mendel,
  14675. XHaruhiko Okumura,
  14676. XJoe Orost,
  14677. XSamuel H. Smith,
  14678. XYooichi Tagawa,
  14679. XSpencer W. Thomas,
  14680. XKen Turkowski,
  14681. XAllan G. Weber,
  14682. XJames A. Woods and
  14683. XHaruyasu Yoshizaki.
  14684. SHAR_EOF
  14685. if test 2386 -ne "`wc -c < 'macunpack.1'`"
  14686. then
  14687.     echo shar: "error transmitting 'macunpack.1'" '(should have been 2386 characters)'
  14688. fi
  14689. fi
  14690. echo shar: "extracting 'hexbin.1'" '(2830 characters)'
  14691. if test -f 'hexbin.1'
  14692. then
  14693.     echo shar: "will not over-write existing file 'hexbin.1'"
  14694. else
  14695. sed 's/^X//' << \SHAR_EOF > 'hexbin.1'
  14696. X.TH MACUNPACK L "July 13, 1991"
  14697. X.UC
  14698. X.SH NAME
  14699. Xhexbin \- Macintosh file de-debinhexer
  14700. X.SH SYNOPSIS
  14701. X.B hexbin
  14702. X[
  14703. X.B \- options
  14704. X] [ files ]
  14705. X.br
  14706. X.SH DESCRIPTION
  14707. X.I hexbin
  14708. Xtakes the specified text file specified in
  14709. X.I files
  14710. X(or standard input if none is specified) and converts the files it
  14711. Xcontains subject to the
  14712. X.I options
  14713. Xspecified.
  14714. X.SH OPTIONS
  14715. XIn the absence of any options,
  14716. X.I hexbin
  14717. Xtakes the specified files and silently converts the file(s) it contains
  14718. Xinto MacBinary format, giving the output files ".bin" extensions and
  14719. Xplacing them in the current working directory.
  14720. X.TP
  14721. X.B \-3 
  14722. XWrite files in fork format (.info, .data and .rsrc files)
  14723. X.TP
  14724. X.B \-f 
  14725. XAs -3, but empty data and rsrc files are not created
  14726. X.TP
  14727. X.B \-r
  14728. XWrite resource forks only (.rsrc files)
  14729. X.TP
  14730. X.B \-d
  14731. XWrite data forks only (.data files)
  14732. X.TP
  14733. X.B \-u
  14734. XAs -d, but the codes for CR and LF are interchanged
  14735. X.TP
  14736. X.B \-a
  14737. XWrite files in AUFS format.
  14738. XThis option is only valid if the program is compiled with AUFS support.
  14739. XThe current directory must be a valid AUFS folder.
  14740. X.TP
  14741. X.B \-s
  14742. XWrite extracted files to standard output in MacBinary format.
  14743. X.TP
  14744. X.B \-l
  14745. XList every file extracted (and every directory/folder created etc.)
  14746. X.TP
  14747. X.B \-v
  14748. XLike -l, but more verbose.
  14749. XWhen this option is specified all lines skipped because they do not
  14750. Xbelong to the hexified format are listed (Implies -l)
  14751. X.TP
  14752. X.B \-i
  14753. XDo not convert, give information only (Implies -l)
  14754. X.TP
  14755. X.B \-c
  14756. XDo not check whether the hexified lines have equal size.
  14757. XNormally the hexifiers gives text files with equal length line size,
  14758. Xhexbin uses this in its heuristics to determine whether a line must
  14759. Xbe skipped.
  14760. XThere are however hexified files that do not conform to that pattern.
  14761. XIf this option is specified hexbin will in general be unable to detect
  14762. Xwhether a line is garbage or not, so you have to remove the garbage by
  14763. Xhand.
  14764. X.TP
  14765. X.B \-n name
  14766. XGives the Unix base file name for the converted files.
  14767. XFor files hexified with BinHex 4.0 or compatible hexifiers this flag
  14768. Xis not needed; hexbin will determine the Unix file name based on the
  14769. XMac file name.
  14770. XFor files in dl, hex or hcx format this parameter may be needed as
  14771. Xthese formats do not include the Mac filename.
  14772. XNormally hexbin will in those cases base the Unix file name on the
  14773. Xtext file name, but that can be overruled with this parameter.
  14774. X.TP
  14775. X.B \-V
  14776. XGives the patchlevel of the program, and other information.
  14777. XOther options are ignored and the program quits immediately.
  14778. X.TP
  14779. X.B \-H
  14780. XGive short information about the options.
  14781. XOther options are ignored and the program quits immediately.
  14782. X.SH BUGS
  14783. XAs this is a beta release, there may still be some problems.
  14784. X.SH AUTHOR
  14785. XDik T. Winter, Amsterdam, The Netherlands (dik@cwi.nl)
  14786. X.sp 1
  14787. XParts of the code are based on codes from:
  14788. Xahm (?),
  14789. XDarin Adler,
  14790. XJim Budler,
  14791. XDave Johnson,
  14792. XDan LaLiberte,
  14793. XJeff Meyer,
  14794. XGuido van Rossum.
  14795. SHAR_EOF
  14796. if test 2830 -ne "`wc -c < 'hexbin.1'`"
  14797. then
  14798.     echo shar: "error transmitting 'hexbin.1'" '(should have been 2830 characters)'
  14799. fi
  14800. fi
  14801. echo shar: "extracting 'macsave.1'" '(1784 characters)'
  14802. if test -f 'macsave.1'
  14803. then
  14804.     echo shar: "will not over-write existing file 'macsave.1'"
  14805. else
  14806. sed 's/^X//' << \SHAR_EOF > 'macsave.1'
  14807. X.TH MACUNPACK L "July 13, 1991"
  14808. X.UC
  14809. X.SH NAME
  14810. Xmacsave \- Save Mac files read fromn standard input
  14811. X.SH SYNOPSIS
  14812. X.B macsave
  14813. X[
  14814. X.B \- options
  14815. X]
  14816. X.br
  14817. X.SH DESCRIPTION
  14818. X.I macsave
  14819. Xreads a sequence of Macintosh MacBinary files from standard input and writes
  14820. Xthe files it contains subject to the
  14821. X.I options
  14822. Xspecified.
  14823. X.SH OPTIONS
  14824. XIn the absence of any options,
  14825. X.I macsave
  14826. Xreads standard input and silently writes the file(s) it contains
  14827. Xinto MacBinary format, giving the output files ".bin" extensions and
  14828. Xplacing them in the current working directory.
  14829. XSubdirectories are created for embedded folders.
  14830. X.TP
  14831. X.B \-3 
  14832. XWrite files in fork format (.info, .data and .rsrc files)
  14833. X.TP
  14834. X.B \-f 
  14835. XAs -3, but empty data and rsrc files are not created
  14836. X.TP
  14837. X.B \-r
  14838. XWrite resource forks only (.rsrc files)
  14839. X.TP
  14840. X.B \-d
  14841. XWrite data forks only (.data files)
  14842. X.TP
  14843. X.B \-u
  14844. XAs -d, but the codes for CR and LF are interchanged
  14845. X.TP
  14846. X.B \-a
  14847. XWrite files in AUFS format.
  14848. XThis option is only valid if the program is compiled with AUFS support.
  14849. XThe current directory must be a valid AUFS folder.
  14850. X.TP
  14851. X.B \-s
  14852. XWrite extracted files to standard output in MacBinary format.
  14853. X.TP
  14854. X.B \-l
  14855. XList every file extracted (and every directory/folder created etc.)
  14856. X.TP
  14857. X.B \-v
  14858. XLike -l, but more verbose (Implies -l)
  14859. X.TP
  14860. X.B \-i
  14861. XDo not extract, give information only (Implies -l)
  14862. X.TP
  14863. X.B \-q
  14864. XAsk the user for every file/folder whether it should be extracted
  14865. X(implies -l)
  14866. X.TP
  14867. X.B \-V
  14868. XGives the patchlevel of the program, and other information.
  14869. XOther options are ignored and the program quits immediately.
  14870. X.TP
  14871. X.B \-H
  14872. XGive short information about the options.
  14873. XOther options are ignored and the program quits immediately.
  14874. X.SH BUGS
  14875. XAs this is a beta release, there may still be some problems.
  14876. X.SH AUTHOR
  14877. XDik T. Winter, Amsterdam, The Netherlands (dik@cwi.nl)
  14878. SHAR_EOF
  14879. if test 1784 -ne "`wc -c < 'macsave.1'`"
  14880. then
  14881.     echo shar: "error transmitting 'macsave.1'" '(should have been 1784 characters)'
  14882. fi
  14883. fi
  14884. echo shar: "done with directory 'man'"
  14885. cd ..
  14886. if test ! -d 'doc'
  14887. then
  14888.     echo shar: "creating directory 'doc'"
  14889.     mkdir 'doc'
  14890. fi
  14891. echo shar: "entering directory 'doc'"
  14892. cd 'doc'
  14893. echo shar: "extracting 'README'" '(21641 characters)'
  14894. if test -f 'README'
  14895. then
  14896.     echo shar: "will not over-write existing file 'README'"
  14897. else
  14898. sed 's/^X//' << \SHAR_EOF > 'README'
  14899. XThis is version 2.0b1 of macutil (26-APR-1992).
  14900. X
  14901. XThis package contains the following utilities:
  14902. X    macunpack
  14903. X    hexbin
  14904. X    macsave
  14905. X
  14906. XRequirements:
  14907. Xa.  Of course a C compiler.
  14908. Xb.  A 32-bit machine with large memory (or at least the ability to 'malloc'
  14909. X    large chunks of memory).  For reasons of efficiency and simplicity the
  14910. X    programs work 'in-core', also many files are first read in core.
  14911. X    If somebody can take the trouble to do it differently, go ahead!
  14912. X    There are also probably in a number of places implicit assumptions that
  14913. X    an int is 32 bits.  If you encounter such occurrences feel free to
  14914. X    notify me.
  14915. Xc.  A Unix (tm) machine, or something very close.  There are probably quite
  14916. X    a lot of Unix dependencies.  Also here, if you have replacements, feel
  14917. X    free to send comments.
  14918. Xd.  This version normally uses the 'mkdir' system call available on BSD Unix
  14919. X    and some versions of SysV Unix.  You can change that, see the makefile for
  14920. X    details.
  14921. X
  14922. XFile name translation:
  14923. X
  14924. XThe programs use a table driven program to do Mac filename -> Unix filename
  14925. Xtranslation.  When compiled without further changes the translation is as
  14926. Xfollows:
  14927. X    Printable ASCII characters except space and slash are not changed.
  14928. X    Slash and space are changed to underscore, as are all characters that
  14929. X    do not fall in the following group.
  14930. X    Accented letters are translated to their unaccented counterparts.
  14931. XIf your system supports the Latin-1 character set, you can change this
  14932. Xtranslation scheme by specifying '-DLATIN1' for the 'CF' macro in the
  14933. Xmakefile.  This will translate all accented letters (and some symbols)
  14934. Xto their Latin-1 counterpart.  This feature is untested (I do not have
  14935. Xaccess to systems that cater for Latin-1), so use with care.
  14936. XFuture revisions of the program will have user settable conversions.
  14937. X
  14938. XAnother feature of filename translation is that when the -DNODOT flag is
  14939. Xspecified in the CF macro an initial period will be translated to underscore.
  14940. X
  14941. XAppleshare support:
  14942. X
  14943. XOptionally the package can be compiled for systems that support the sharing
  14944. Xof Unix and Mac filesystems.  The package supports AUFS (AppleTalk Unix File
  14945. XServer) from CAP (Columbia AppleTalk Package) and AppleDouble (from Apple).
  14946. XIt will not support both at the same time.  Moreover this support requires
  14947. Xthe existence of the 'mkdir' system call.  And finally, as implemented it
  14948. Xprobably will work on big-endian BSD compatible systems.  If you have a SysV
  14949. Xsystem with restricted filename lengths you can get problems.  I do not know
  14950. Xalso whether the structures are stored native or Apple-wise on little-endian
  14951. Xsystems.  And also, I did not test it fully; having no access to either AUFS
  14952. Xor AppleDouble systems.
  14953. X
  14954. XAcknowledgements:
  14955. Xa.  Macunpack is for a large part based on the utilities 'unpit' and 'unsit'
  14956. X    written by:
  14957. X    Allan G. Weber
  14958. X    weber%brand.usc.edu@oberon.usc.edu
  14959. X    (wondering whether that is still valid!).  I combined the two into a
  14960. X    single program and did a lot of modification.  For information on the
  14961. X    originals, see the files README.unpit and README.unsit.
  14962. Xb.  The crc-calculating routines are based on a routine originally written by:
  14963. X    Mark G. Mendel
  14964. X    UUCP: ihnp4!umn-cs!hyper!mark
  14965. X    (this will not work anymore for sure!).  Also here I modified the stuff
  14966. X    and expanded it, see the files README.crc and README.crc.orig.
  14967. Xc.  LZW-decompression is taken from the sources of compress that are floating
  14968. X    around.  Probably I did not use the most efficient version, but this
  14969. X    program was written to get it done.  The version I based it on (4.0) is
  14970. X    authored by:
  14971. X    Steve Davies            (decvax!vax135!petsd!peora!srd)
  14972. X    Jim McKie               (decvax!mcvax!jim)  (Hi Jim!)
  14973. X    Joe Orost               (decvax!vax135!petsd!joe)
  14974. X    Spencer W. Thomas       (decvax!harpo!utah-cs!utah-gr!thomas)
  14975. X    Ken Turkowski           (decvax!decwrl!turtlevax!ken)
  14976. X    James A. Woods          (decvax!ihnp4!ames!jaw)
  14977. X    I am sure those e-mail addresses also will not work!
  14978. Xd.  Optional AUFS support comes from information supplied by:
  14979. X    Casper H.S. Dik
  14980. X    University of Amsterdam
  14981. X    Kruislaan  409
  14982. X    1098 SJ  Amsterdam
  14983. X    Netherlands
  14984. X
  14985. X    phone: +31205922022
  14986. X    email: casper@fwi.uva.nl
  14987. X    This is an e-mail address that will work.
  14988. X    See the makefile.
  14989. X    Some caveats are applicable:
  14990. X    1.  I did not fully test it (we do not use it).  But the unpacking
  14991. X    appears to be correct.  Anyhow, as the people who initially compile
  14992. X    it and use it will be system administrators I am confident they are
  14993. X    able to locate bugs!  (What if an archive contains a Macfile with
  14994. X    the name .finderinfo or .resource?  I have had two inputs for AUFS
  14995. X    support [I took Caspers; his came first], but both do not deal with
  14996. X    that.  Does CAP deal with it?)  Also I have no idea whether this
  14997. X    version supports it under SysV, so beware.
  14998. X    2.    From one of the README's supplied by Casper:
  14999. X        Files will not appear in an active folder, because Aufs doesn't like
  15000. X        people working behind it's back.
  15001. X        Simply opening and closing the folder will suffice.
  15002. X    Appears to be the same problem as when you are unpacking or in some
  15003. X    other way creating files in a folder open to multifinder.  I have seen
  15004. X    bundle bits disappear this way.  So if after unpacking you see the
  15005. X    generic icon; check whether a different icon should appear and check
  15006. X    the bundle bit.
  15007. X        The desktop isn't updated, but that doesn't seem to matter. 
  15008. X    I dunno, not using it.
  15009. Xe.  Man pages are now supplied.  The base was provided by:
  15010. X    Douglas Siebert
  15011. X    ISCA
  15012. X    dsiebert@icaen.uiowa.edu
  15013. Xf.  Because of some problems the Uncompactor has been rewritten, it is now
  15014. X    based on sources from the dearchiver unzip (of PC fame).  Apparently the
  15015. X    base code is by:
  15016. X    Samuel H. Smith
  15017. X    I have no further address available, but as soon as I find a better
  15018. X    attribution, I will include it.
  15019. Xg.  UnstuffIt's LZAH code comes from lharc (also of PC fame) by:
  15020. X    Haruhiko Okumura,
  15021. X    Haruyasu Yoshizaki,
  15022. X    Yooichi Tagawa.
  15023. Xh.  Zoom's code comes from information supplied by Jon W{tte
  15024. X    (d88-jwa@nada.kth.se).  The Zoo decompressor is based on the routine
  15025. X    written by Rahul Dhesi (dhesi@cirrus.COM).  This again is based on
  15026. X    code by Haruhiko Okumura.  See also the file README.zoom.
  15027. Xi.  MacLHa's decompressors are identical to the ones mentioned in g and h.
  15028. Xj.  Most of hexbin's code is based on code written/modified by:
  15029. X    Dave Johnson, Brown University Computer Science
  15030. X    Darin Adler, TMQ Software
  15031. X    Jim Budler, amdcad!jimb
  15032. X    Dan LaLiberte, liberte@uiucdcs
  15033. X    ahm (?)
  15034. X    Jeff Meyer, John Fluke Company
  15035. X    Guido van Rossum, guido@cwi.nl (Hi!)
  15036. X    (most of the e-mail addresses will not work, the affiliation may also
  15037. X    be incorrect by now.)  See also the file README.hexbin.
  15038. Xk.  The dl code in hexbin comes is based on the original distribution of
  15039. X    SUMacC.
  15040. Xl.  The mu code in hexbin is a slight modification of the hcx code (the
  15041. X    compressions are identical).
  15042. Xm.  The MW code for StuffIt is loosely based on code by Daniel H. Bernstein
  15043. X    (brnstnd@acf10.nyu.edu).
  15044. X
  15045. X-------------------------------------------------------------------------------
  15046. XMacunpack will unpack PackIt, StuffIt, Diamond, Compactor/Compact Pro, most
  15047. XStuffItClassic/StuffItDeluxe, and all Zoom and LHarc/MacLHa archives.
  15048. XAlso it will decode files created by BinHex5.0, MacBinary, UMCP,
  15049. XCompress It, ShrinkToFit, MacCompress and DiskDoubler.
  15050. X
  15051. X(PackIt, StuffIt, Diamond, Compactor, Compact/Pro, Zoom and LHarc/MacLHa are
  15052. Xarchivers written by respectively: Harry R. Chesley, Raymond Lau, Denis Sersa,
  15053. XBill Goodman, Jon W{tte* and Kazuaki Ishizaki.  BinHex 5.0, MacBinary and
  15054. XUMCP are by respectively: Yves Lempereur, Gregory J. Smith, Information
  15055. XElectronics.  ShrinkToFit is by Roy T. Hashimoto, Compress It by Jerry
  15056. XWhitnell, and MacCompress and DiskDoubler are both by Lloyd Chambers.)
  15057. X
  15058. X* from his signature:
  15059. X    Jon W{tte - Yes, that's a brace - Damn Swede.
  15060. XActually it is an a with two dots above; some (German inclined) people
  15061. Xrefer to it (incorrectly) as a-umlaut.
  15062. X
  15063. XIt does not deal with:
  15064. Xa.  Password protected archives.
  15065. Xb.  Multi-segment archives.
  15066. Xc.  Plugin methods for Zoom.
  15067. Xd.  MacLHa archives not packed in MacBinary mode (the program deals very
  15068. X    poorly with that!).
  15069. X
  15070. XBackground:
  15071. XThere are millions of ways to pack files, and unfortunately, all have been
  15072. Ximplemented one way or the other.  Below I will give some background
  15073. Xinformation about the packing schemes used by the different programs
  15074. Xmentioned above.  But first some background about compression (I am no
  15075. Xexpert, more comprehensive information can be found in for instance:
  15076. XTomothy Bell, Ian H. Witten and John G. Cleary, Modelling for Text
  15077. XCompression, ACM Computing Surveys, Vol 21, No 4, Dec 1989, pp 557-591).
  15078. X
  15079. XHuffman encoding (also called Shannon-Fano coding or some other variation
  15080. X    of the name).  An encoding where the length of the code for the symbols
  15081. X    depends on the frequency of the symbols.  Frequent symbols have shorter
  15082. X    codes than infrequent symbols.  The normal method is to first scan the
  15083. X    file to be compressed, and to assign codes when this is done (see for
  15084. X    instance: D. E. Knuth, the Art of Computer Programming).  Later methods
  15085. X    have been designed to create the codes adaptively; for a survey see:
  15086. X    Jeremy S. Vetter, Design and Analysis of Dynamic Huffman Codes, JACM,
  15087. X    Vol 34, No 4, Oct 1987, pp 825-845.
  15088. XLZ77: The first of two Ziv-Lempel methods.  Using a window of past encoded
  15089. X    text, output consists of triples for each sequence of newly encoded
  15090. X    symbols: a back pointer and length of past text to be repeated and the
  15091. X    first symbol that is not part of that sequence.  Later versions allowed
  15092. X    deviation from the strict alternation of pointers and uncoded symbols
  15093. X    (LZSS by Bell).  Later Brent included Huffman coding of the pointers
  15094. X    (LZH).
  15095. XLZ78: While LZ77 uses a window of already encoded text as a dictionary,
  15096. X    LZ78 dynamically builds the dictionary.  Here again pointers are strictly
  15097. X    alternated with unencoded new symbols.  Later Welch (LZW) managed to
  15098. X    eliminate the output of unencoded symbols.  This algorithm is about
  15099. X    the same as the one independently invented by Miller and Wegman (MW).
  15100. X    A problem with these two schemes is that they are patented.  Thomas
  15101. X    modified LZW to LZC (as used in the Unix compress command).  While LZ78
  15102. X    and LZW become static once the dictionary is full, LZC has possibilities
  15103. X    to reset the dictionary.  Many LZC variants are in use, depending on the
  15104. X    size of memory available.  They are distinguished by the maximum number
  15105. X    of bits that are used in a code.
  15106. XA number of other schemes are proposed and occasionally used.  The main
  15107. Xadvantage of the LZ type schemes is that (especially) decoding is fairly fast.
  15108. X
  15109. XPrograms background:
  15110. X
  15111. XPlain programs:
  15112. XBinHex 5.0:
  15113. X    Unlike what its name suggest this is not a true successor of BinHex 4.0.
  15114. X    BinHex 5.0 takes the MacBinary form of a file and stores it in the data
  15115. X    fork of the newly created file.
  15116. X    Although BinHex 5.0 does not create BinHex 4.0 compatible files, StuffIt
  15117. X    will give the creator type of BinHex 5.0 (BnHq) to its binhexed files,
  15118. X    rather than the creator type of BinHex 4.0 (BNHQ).  The program knows
  15119. X    about that.
  15120. XMacBinary:
  15121. X    As its name suggests, it does the same as BinHex 5.0.
  15122. XUMCP:
  15123. X    Looks similar, but the file as stored by UMCP is not true MacBinary.
  15124. X    Size fields are modified, the result is not padded to a multiple of 128,
  15125. X    etc.  Macunpack deals with all that, but until now is not able to
  15126. X    correctly restore the finder flags of the original file.  Also, UMCP
  15127. X    created files have type "TEXT" and creator "ttxt", which can create a
  15128. X    bit of confusion.  Macunpack will recognize these files only if the
  15129. X    creator has been modified to "UMcp".
  15130. X
  15131. XCompressors:
  15132. XShrinkToFit:
  15133. X    This program uses a Huffman code to compress.  It has an option (default
  15134. X    checked for some reason), COMP, for which I do not yet know the
  15135. X    meaning.  Compressing more than a single file in a single run results
  15136. X    in a failure for the second and subsequent files.
  15137. XCompress It:
  15138. X    Also uses a Huffman code to compress.
  15139. XMacCompress:
  15140. X    MacCompress has two modes of operation, the first mode is (confusingly)
  15141. X    MacCompress, the seecond mode is (again confusingly) UnixCompress.  In
  15142. X    MacCompress mode both forks are compressed using the LZC algorithm.
  15143. X    In UnixCompress mode only the data fork is compressed, and some shuffling
  15144. X    of resources is performed.  Upto now macunpack only deals with MacCompress
  15145. X    mode.  The LZC variant MacCompress uses depends on memory availability.
  15146. X    12 bit to 16 bit LZC can be used.
  15147. X
  15148. XArchivers:
  15149. XArcMac:
  15150. X    Nearly PC-Arc compatible.  Arc knows 8 compression methods, I have seen
  15151. X    all of them used by ArcMac, except the LZW techniques.  Here they are:
  15152. X    1:    No compression, shorter header
  15153. X    2:    No compression
  15154. X    3:    (packing) Run length encoding
  15155. X    4:    (squeezing) RLE followed by Huffman encoding
  15156. X    5:    (crunching) LZW
  15157. X    6:    (crunching) RLE followed by LZW
  15158. X    7:    (crunching) as the previous but with a different hash function
  15159. X    8:    (crunching) RLE followed by 12-bit LZC
  15160. X    9:    (squashing) 13-bit LZC
  15161. XPackIt:
  15162. X    When archiving a file PackIt either stores the file uncompressed or
  15163. X    stores the file Huffman encoded.  In the latter case both forks are
  15164. X    encoded using the same Huffman tree.
  15165. XStuffIt and StuffIt Classic/Deluxe:
  15166. X    These have the ability to use different methods for the two forks of a
  15167. X    file.  The following standard methods I do know about (the last three
  15168. X    are only used by the Classic/Deluxe version 2.0 of StuffIt):
  15169. X    0:    No compression
  15170. X    1:    Run length encoding
  15171. X    2:    14-bit LZC compression
  15172. X    3:    Huffman encoding
  15173. X    5:    LZAH: like LZH, but the Huffman coding used is adaptive
  15174. X    6:    A Huffman encoding using a fixed (built-in) Huffman tree
  15175. X    8:    A MW encoding
  15176. XDiamond:
  15177. X    Uses a LZ77 like frontend plus a Fraenkel-Klein like backend (see
  15178. X    Apostolico & Galil, Combinatorial Algorithms on Words, pages 169-183).
  15179. XCompactor/Compact Pro:
  15180. X    Like StuffIt, different encodings are possible for data and resource fork.
  15181. X    Only two possible methods are used:
  15182. X    0:    Run length encoding
  15183. X    1:    RLE followed by some form of LZH
  15184. XZoom:
  15185. X    Data and resource fork are compressed with the same method.  The standard
  15186. X    uses either no compression or some form of LZH
  15187. XMacLHa:
  15188. X    Has two basic modes of operation, Mac mode and Normal mode.  In Mac mode
  15189. X    the file is archived in MacBinary form.  In normal mode only the forks
  15190. X    are archived.  Normal mode should not be used (and can not be unpacked
  15191. X    by macunpack) as all information about data fork size/resource fork size,
  15192. X    type, creator etc. is lost.  It knows quite a few methods, some are
  15193. X    probably only used in older versions, the only methods I have seen used
  15194. X    are -lh0-, -lh1- and -lh5-.  Methods known by MacLHa:
  15195. X    -lz4-:  No compression
  15196. X    -lz5-:  LZSS
  15197. X    -lzs-:  LZSS, another variant
  15198. X    -lh0-:  No compression
  15199. X    -lh1-:  LZAH (see StuffIt)
  15200. X    -lh2-:  Another form of LZAH
  15201. X    -lh3-:  A form of LZH, different from the next two
  15202. X    -lh4-:  LZH with a 4096 byte buffer (as far as I can see the coding in
  15203. X        MacLHa is wrong)
  15204. X    -lh5-:  LZH with a 8192 byte buffer
  15205. XDiskDoubler:
  15206. X    The older version of DiskDoubler is compatible with MacCompress.  It does
  15207. X    not create archives, it only compresses files.  The newer version (since
  15208. X    3.0) does both archiving and compression.  The older version uses LZC as
  15209. X    its compression algorithm, the newer version knows a number of different
  15210. X    compression algorithms.  Many (all?) are algorithms used in other
  15211. X    archivers.  Probably this is done to simplify conversion from other formats
  15212. X    to DiskDoubler format archives.  I have seen actual DiskDoubler archives
  15213. X    that used methods 0, 1 and 8:
  15214. X    0:    No compression
  15215. X    1:    LZC
  15216. X    2:    ???
  15217. X    3:    RLE
  15218. X    4:    Huffman (or no compression)
  15219. X    5:    ???
  15220. X    6:    ???
  15221. X    7:    An improved form of LZSS
  15222. X    8:    Compactor/Compact Pro compatible RLE/LZH or RLE only
  15223. X    9:    ???
  15224. X    The DiskDoubler archive format contains many subtle twists that make it
  15225. X    difficult to properly read the archive (or perhaps this is on purpose?).
  15226. X
  15227. XNaming:
  15228. XSome people have complained about the name conflict with the unpack utility
  15229. Xthat is already available on Sys V boxes.  I had forgotten it, so there
  15230. Xreally was a problem.  The best way to solve it was to trash pack/unpack/pcat
  15231. Xand replace it by compress/uncompress/zcat.  Sure, man uses it; but man uses
  15232. Xpcat, so you can retain pcat.  If that was not an option you were able to feel
  15233. Xfree to rename the program.  But finally I relented.  It is now macunpack.
  15234. X
  15235. XWhen you have problems unpacking an archive feel free to ask for information.
  15236. XI am especially keen when the StuffIt part detects Fixed Huffman or bigram
  15237. Xcompression methods.  If you encounter such an archive, please, mail a
  15238. X'binhexed' copy of the archive to me so that I can deal with it.  Password
  15239. Xprotected archives are (as already stated) not implemented.  I do not have much
  15240. Xinclination to do that.  Also I feel no inclination to do multi-segment
  15241. Xarchives.
  15242. X
  15243. X-------------------------------------------------------------------------------
  15244. XHexbin will de-hexify files created in BinHex 4.0 compatible format (hqx)
  15245. Xbut also the older format (dl, hex and hcx).  Moreover it will uudecode
  15246. Xfiles uuencoded by UUTool (the only program I know that does UU hexification
  15247. Xof all Mac file information).
  15248. X
  15249. XThere are currently many programs that are able to create files in BinHex 4.0
  15250. Xcompatible format.  There are however some slight differences, and most
  15251. Xde-hexifiers are not able to deal with all the variations.  This program is
  15252. Xvery simple minded.  First it will intuit (based on the input) whether the
  15253. Xfile is in dl, hex, hcx or hqx format.  Next it will de-hexify the file.
  15254. XWhen the format is hqx, it will check whether more files follow, and continue
  15255. Xprocessing.  So you can catenate multiple (hqx) hexified files together and
  15256. Xfeed them as a single file to hexbin.  Also hexbin does not mind whether lines
  15257. Xare separated by CR's, LF's or combinations of the two.  Moreover, it will
  15258. Xstrip all leading, trailing and intermediate garbage introduced by mailers
  15259. Xetc.  Next, it does not mind if a file is not terminated by a CR or an LF
  15260. X(as StuffIt 1.5.1 and earlier did), but in that case a second file is not
  15261. Xallowed to follow it.  Last, while most hexifiers output lines of equal length,
  15262. Xsome do not.  Hexbin will deal with that, but there are some caveats; see the
  15263. X-c option in the man page.
  15264. X
  15265. XBackground:
  15266. X
  15267. Xdl format:
  15268. X    This was the first hexified format used.  Programs to deal with it came
  15269. X    from SUMacC.  This format only coded resource forks, 4 bits in a byte.
  15270. Xhex format:
  15271. X    I think this is the first format from Yves Lempereur.  Like dl format,
  15272. X    it codes 4 bits in a byte, but is able to code both resource and
  15273. X    data fork.  Is it BinHex 2.0?
  15274. Xhcx format:
  15275. X    A compressing variant of hex format.  Codes 6 bits in a byte.
  15276. X    Is it BinHex 3.0?
  15277. Xhqx format:
  15278. X    Like hcx, but using a different coding (possibly to allow for ASCII->EBCDIC
  15279. X    and EBCDIC->ASCII translation, which not always results in an identical
  15280. X    file).  Moreover this format also encodes the original Mac filename.
  15281. Xmu format:
  15282. X    The conversion can be done by the UUTool program from Octavian Micro
  15283. X    Development.  It encodes both forks and also some finder info.  You will
  15284. X    in general not use this with uudecode on non Mac systems, with uudecode
  15285. X    only the data fork will be uudecoded.  UU hexification is well known (and
  15286. X    fairly old) in Unix environments.  Moreover it has been ported to lots of
  15287. X    other systems.
  15288. X-------------------------------------------------------------------------------
  15289. XMacsave will read a MacBinary stream from standard input and writes the
  15290. Xfiles according to the options.
  15291. X-------------------------------------------------------------------------------
  15292. XThis is an ongoing project, more stuff will appear.
  15293. X
  15294. XAll comments are still welcome.  Thanks for the comments I already received.
  15295. X
  15296. Xdik t. winter, amsterdam, nederland
  15297. Xemail: dik@cwi.nl
  15298. X
  15299. X--
  15300. XNote:
  15301. XIn these programs all algorithms are implemented based on publicly available
  15302. Xsoftware to prevent any claim that would prevent redistribution due to
  15303. XCopyright.  Although parts of the code would indeed fall under the Copyright
  15304. Xby the original author, use and redistribution of all such code is explicitly
  15305. Xallowed.  For some parts of it the GNU software license does apply.
  15306. X--
  15307. XAppendix.
  15308. X
  15309. XBinHex 4.0 compatible file creators:
  15310. X
  15311. XType    Creator        Created by
  15312. X
  15313. X"TEXT"    "BthX"        BinHqx
  15314. X"TEXT"    "BNHQ"        BinHex
  15315. X"TEXT"    "BnHq"        StuffIt and StuffIt Classic
  15316. X"TEXT"    "ttxt"        Compactor
  15317. X
  15318. XFiles recognized by macunpack:
  15319. X
  15320. XType    Creator        Recognized as
  15321. X
  15322. X"APPL"    "DSEA"        "DiskDoubler"        Self extracting
  15323. X"APPL"    "EXTR"        "Compactor"        Self extracting
  15324. X"APPL"    "Mooz"        "Zoom"            Self extracting
  15325. X"APPL"    "Pack"        "Diamond"        Self extracting
  15326. X"APPL"    "arc@"        "ArcMac"        Self extracting (not yet)
  15327. X"APPL"    "aust"        "StuffIt"        Self extracting
  15328. X"ArCv"    "TrAS"        "AutoSqueeze"                (not yet)
  15329. X"COMP"    "STF "        "ShrinkToFit"
  15330. X"DD01"    "DDAP"        "DiskDoubler"
  15331. X"DDAR"    "DDAP"        "DiskDoubler"
  15332. X"DDF."    "DDAP"        "DiskDoubler" (any fourth character)
  15333. X"DDf."    "DDAP"        "DiskDoubler" (any fourth character)
  15334. X"LARC"    "LARC"        "MacLHa (LHARC)"
  15335. X"LHA "    "LARC"        "MacLHa (LHA)"
  15336. X"PACT"    "CPCT"        "Compactor"
  15337. X"PIT "    "PIT "        "PackIt"
  15338. X"Pack"    "Pack"        "Diamond"
  15339. X"SIT!"    "SIT!"        "StuffIt"
  15340. X"SITD"    "SIT!"        "StuffIt Deluxe"
  15341. X"Smal"    "Jdw "        "Compress It"
  15342. X"TEXT"    "BnHq"        "BinHex 5.0"
  15343. X"TEXT"    "GJBU"        "MacBinary 1.0"
  15344. X"TEXT"    "UMcp"        "UMCP"
  15345. X"ZIVM"    "LZIV"        "MacCompress(M)"
  15346. X"ZIVU"    "LZIV"        "MacCompress(U)"            (not yet)
  15347. X"mArc"    "arc*"        "ArcMac"                (not yet)
  15348. X"zooM"    "zooM"        "Zoom"
  15349. X
  15350. SHAR_EOF
  15351. if test 21641 -ne "`wc -c < 'README'`"
  15352. then
  15353.     echo shar: "error transmitting 'README'" '(should have been 21641 characters)'
  15354. fi
  15355. fi
  15356. echo shar: "extracting 'README.unpit'" '(2202 characters)'
  15357. if test -f 'README.unpit'
  15358. then
  15359.     echo shar: "will not over-write existing file 'README.unpit'"
  15360. else
  15361. sed 's/^X//' << \SHAR_EOF > 'README.unpit'
  15362. X/*
  15363. X *    @(#)unpit.c    1.2    (CWI)    87/11/05
  15364. X */
  15365. X
  15366. X/*
  15367. X
  15368. X        unpit - Macintosh PackIt file unpacker
  15369. X
  15370. X        Version 2, for PackIt II
  15371. X
  15372. XThis program will unpack a Macintosh PackIt file into separate files.  The
  15373. Xdata fork of a PackIt file contains both the data and resource forks of the
  15374. Xpacked files.  The program will unpack each Mac file into separate .data,
  15375. X.rsrc., and .info files that can be downloaded to a Mac using macput.
  15376. X
  15377. XThe program syntax is much like macput/macget:
  15378. X
  15379. X    unpit [-rdu] packit-file.data
  15380. X
  15381. XThe  -r and -d flags will cause only the resource and data forks to be
  15382. Xwritten.  The -u flag will cause only the data fork to be written and
  15383. Xto have carriage return characters changed to Unix newline characters.
  15384. X
  15385. XSome of the program is borrowed from the macput.c/macget.c programs.
  15386. X
  15387. X    Author: Allan G. Weber, (Weber%Brand@USC-ECL)        
  15388. X    Date:   September 30, 1985
  15389. X    Revised: January 24, 1986 - added CRC checking
  15390. X         March 25, 1986 - support compressed mode of PackIt II,
  15391. X                  check for illegal Unix file names
  15392. X
  15393. X*/
  15394. X
  15395. X/* There is some confusion as to what to do with the "inited" flag in the
  15396. X   finder info bytes that are in the header of each file in the packit file.
  15397. X   If this flag bit is copied to the .info file, it seems to confuse
  15398. X   MacTerminal into placing the file icons in the upper left corner of the
  15399. X   window on top of each other.  Setting this bit to zero in the .info file
  15400. X   seems to fix that problem but may cause others.  I haven't been able to
  15401. X   find any .info files that have this flag set so making it zero may be OK.
  15402. X   Anyway, MacTerminal seems to set the flag when it create the file on the
  15403. X   Mac.  The "#define INITED_BUG" can be used to try both settings.  */
  15404. X
  15405. X/*
  15406. XFormat of a Packit file:
  15407. X
  15408. XRepeat the following sequence for each file in the Packit file:
  15409. X
  15410. X    4 byte identifier ("PMag" = not compressed, "Pma4" = compressed)
  15411. X    variable length compression data (if compressed file)
  15412. X    92 byte header (see struct pit_header below) *
  15413. X    2 bytes CRC number *
  15414. X    data fork (length from header) *
  15415. X    resource fork (length from header) *
  15416. X    2 bytes CRC number *
  15417. X
  15418. XLast file is followed by the 4 byte Ascii string, "Pend", and then the EOF.
  15419. X
  15420. X* these are in compressed form if compression is on for the file
  15421. X
  15422. X*/
  15423. X
  15424. SHAR_EOF
  15425. if test 2202 -ne "`wc -c < 'README.unpit'`"
  15426. then
  15427.     echo shar: "error transmitting 'README.unpit'" '(should have been 2202 characters)'
  15428. fi
  15429. fi
  15430. echo shar: "extracting 'README.unsit'" '(1916 characters)'
  15431. if test -f 'README.unsit'
  15432. then
  15433.     echo shar: "will not over-write existing file 'README.unsit'"
  15434. else
  15435. sed 's/^X//' << \SHAR_EOF > 'README.unsit'
  15436. X/*
  15437. X        unsit - Macintosh StuffIt file extractor
  15438. X
  15439. X            Version 1, for StuffIt 1.31
  15440. X
  15441. XThis program will unpack a Macintosh StuffIt file into separate files.
  15442. XThe data fork of a StuffIt file contains both the data and resource
  15443. Xforks of the packed files.  The program will unpack each Mac file into
  15444. Xseparate .data, .rsrc., and .info files that can be downloaded to a
  15445. XMac using macput.  The program is much like the "unpit" program for
  15446. Xbreaking apart Packit archive files.
  15447. X
  15448. X            ***** IMPORTANT *****
  15449. XTo extract StuffIt files that have been compressed with the Lempel-Ziv
  15450. Xcompression method, unsit pipes the data through the "compress"
  15451. Xprogram with the appropriate switches, rather than incorporate the
  15452. Xuncompression routines within "unsit".  Therefore, it is necessary to
  15453. Xhave the "compress" program on the system and in the search path to
  15454. Xmake "unsit" work.  "Compress" is available from the comp.sources.unix
  15455. Xarchives.
  15456. X
  15457. XThe program syntax is much like unpit and macput/macget, with some added
  15458. Xoptions:
  15459. X
  15460. X    unsit [-rdulvq] stuffit-file.data
  15461. X
  15462. XThe -r and -d flags will cause only the resource and data forks to be
  15463. Xwritten.  The -u flag will cause only the data fork to be written and
  15464. Xto have carriage return characters changed to Unix newline characters.
  15465. XThe -l flag will make the program only list the files in the StuffIt
  15466. Xfile.  The -v flag causes the program to list the names, sizes, type,
  15467. Xand creators of the files it is writing.  The -q flag causes it to
  15468. Xlist the name, type and size of each file and wait for a 'y' or 'n'
  15469. Xfor either writing that file or skipping it, respectively.
  15470. X
  15471. XSome of the program is borrowed from the macput.c/macget.c programs.
  15472. XMany, many thanks to Raymond Lau, the author of StuffIt, for including 
  15473. Xinformation on the format of the StuffIt archives in the documentation.
  15474. X
  15475. X    Author: Allan G. Weber
  15476. X        weber%brand.usc.edu@oberon.usc.edu
  15477. X        ...sdcrdcf!usc-oberon!brand!weber
  15478. X    Date:   January 15, 1988
  15479. X
  15480. X*/
  15481. X
  15482. SHAR_EOF
  15483. if test 1916 -ne "`wc -c < 'README.unsit'`"
  15484. then
  15485.     echo shar: "error transmitting 'README.unsit'" '(should have been 1916 characters)'
  15486. fi
  15487. fi
  15488. echo shar: "extracting 'README.zoom'" '(3389 characters)'
  15489. if test -f 'README.zoom'
  15490. then
  15491.     echo shar: "will not over-write existing file 'README.zoom'"
  15492. else
  15493. sed 's/^X//' << \SHAR_EOF > 'README.zoom'
  15494. XTaken from the file plugins.h in the Zoom distribution.
  15495. X
  15496. X/*
  15497. X * The Zoom archive format is:
  15498. X *
  15499. X * (char) Magic1
  15500. X * (char) Magic2 - or - (char) Magic2B
  15501. X * (char) Magic3
  15502. X * (char) Magic4
  15503. X * 
  15504. X * IF Magic2B was received THEN
  15505. X *        (long) logicalEof /* For multi-file archives * /
  15506. X * END IF
  15507. X * 
  15508. X * <EntryChain>
  15509. X * 
  15510. X * The format of <EntryChain> is a linked list of
  15511. X * EntryInfo, where "next" points to the next logical address
  15512. X * on disk. "next" as 0 means no more entries.
  15513. X *
  15514. X * For a directory, the "creator" field points to the
  15515. X * first file/folder entry inside the directory.
  15516. X *
  15517. X * For a file, IF the "what" field is ZOOM_PLUGIN,
  15518. X * the EntryInfo is followed by a length byte and that
  15519. X * many characters naming the compression engine.
  15520. X * Right after that (or right after the EntryInfo in the
  15521. X * case of uncompressed files or default compressed files)
  15522. X * follows the data fork compressed, followed by the
  15523. X * resource fork compressed.
  15524. X *
  15525. X * Note that there is no "end of compressed data" marker;
  15526. X * your compressor engine will have to figure that out by
  15527. X * itself. You could for instance do an ftell before
  15528. X * compressing; writing a (long)0 and then write your
  15529. X * compressed data, seek back and write the actual length.
  15530. X *
  15531. X * Note that new entries always are added last in the file,
  15532. X * so you need not worry about overrunning anything else.
  15533. X */
  15534. X
  15535. X/*
  15536. X * The default compressor in Zoom is the same as used in
  15537. X * "better" compression mode in ZOO 2.10. A Zoo extractor
  15538. X * or convertor could parse the ZOO header format, and use
  15539. X * the built-in engine for "lzh" compressed files.
  15540. X *
  15541. X * The simplest way to do this is to call SetEngine(-1) and
  15542. X * call Encode / Decode. -1 is the default compressor, 0 is
  15543. X * the null compressor (fork copy)
  15544. X *
  15545. X * Likewise, a UNIX zoom packer/unpacker could use the source
  15546. X * for zoo 2.10 functions "lzh_encode" and "lzh_decode"
  15547. X * (they're wrappers) for compression.
  15548. X */
  15549. X
  15550. X/*
  15551. X * This "EntryInfo" is presently also a file header.
  15552. X * Some fields may be non-obvious. Don't use these.
  15553. X * For instance, "comment" is currently unsupported,
  15554. X * and should be left as 0
  15555. X */
  15556. X#ifndef ZOOM_TYPES
  15557. Xtypedef enum zoomWhatType {
  15558. X    ZOOM_NOTHING , ZOOM_FILE , ZOOM_UCFILE , ZOOM_DIR , ZOOM_PLUGIN
  15559. X} ZoomWhatType ;
  15560. X#define ZOOM_TYPES
  15561. X#endif
  15562. X
  15563. X/*
  15564. X * Remember to fill in "hlen" correctly as well. When reading a header,
  15565. X * Zoom checks with this field to see if it should skip some more data
  15566. X * or seek back a little, so as to make future field additions at the
  15567. X * end possible. You should NOT add your own fields to this structure.
  15568. X */
  15569. Xtypedef struct EntryInfo {
  15570. X
  15571. X    /* "what" is a ZoomWhatType */
  15572. X    char            what ;            /* Negative if deleted */
  15573. X    unsigned char    hlen ;            /* Header length */
  15574. X    unsigned short    boolFlags ;        /* Boolean flags */
  15575. X    long            next ;            /* Next entry */
  15576. X
  15577. X    long            complen ;        /* Length of compressed data */
  15578. X    long            compdata ;        /* Data fork portion of compressed data - for dirs, number of entries */
  15579. X    long            uclen ;            /* Length of uncompressed entry */
  15580. X    long            ucdata ;        /* Data fork part of uncompressed */
  15581. X
  15582. X    long            type ;            /* File type */
  15583. X    long            creator ;        /* File creator - for dir, offset of file */
  15584. X    long            mdate ;            /* Modification date */
  15585. X    long            comment ;        /* Comment offset */
  15586. X    short            flags ;            /* Macintosh file flags */
  15587. X
  15588. X    short            dataCrc ;        /* Data fork crc */
  15589. X    short            resCrc ;        /* Resource fork crc */
  15590. X
  15591. X    unsigned char    name [ 32 ] ;    /* File/Dir name */
  15592. X
  15593. X} EntryInfo ;
  15594. X
  15595. SHAR_EOF
  15596. if test 3389 -ne "`wc -c < 'README.zoom'`"
  15597. then
  15598.     echo shar: "error transmitting 'README.zoom'" '(should have been 3389 characters)'
  15599. fi
  15600. fi
  15601. echo shar: "extracting 'README.hexbin'" '(1421 characters)'
  15602. if test -f 'README.hexbin'
  15603. then
  15604.     echo shar: "will not over-write existing file 'README.hexbin'"
  15605. else
  15606. sed 's/^X//' << \SHAR_EOF > 'README.hexbin'
  15607. XThe comment for the predecessor of hexbin.
  15608. X
  15609. X/*
  15610. X * xbin -- unpack BinHex format file into suitable
  15611. X * format for downloading with macput
  15612. X * Dave Johnson, Brown University Computer Science
  15613. X *
  15614. X * (c) 1984 Brown University
  15615. X * may be used but not sold without permission
  15616. X *
  15617. X * created ddj 12/16/84
  15618. X * revised ddj 03/10/85 -- version 4.0 compatibility, other minor mods
  15619. X * revised ddj 03/11/85 -- strip LOCKED bit from m_flags
  15620. X * revised ahm 03/12/85 -- System V compatibility
  15621. X * revised dba 03/16/85 -- (Darin Adler, TMQ Software)  4.0 EOF fixed,
  15622. X *               4.0 checksum added
  15623. X * revised ddj 03/17/85 -- extend new features to older formats: -l, stdin
  15624. X * revised ddj 03/24/85 -- check for filename truncation, allow multiple files
  15625. X * revised ddj 03/26/85 -- fixed USG botches, many problems w/multiple files
  15626. X * revised jcb 03/30/85 -- (Jim Budler, amdcad!jimb), revised for compatibility
  15627. X *               with 16-bit int machines
  15628. X * revised dl  06/16/85 -- (Dan LaLiberte, liberte@uiucdcs) character
  15629. X *               translation speedup
  15630. X * revised ddj 09/30/85 -- fixed problem with run of RUNCHAR
  15631. X * revised gvr 11/15/86 -- speed-up: rewrote .hqx decoding (mcvax!guido)
  15632. X * revised jwm 04/26/88 -- now recognizes "(Convert with" as a starting line
  15633. X *              -- the widely-used Stuffit uses this as a header
  15634. X * revised dtw ../../89 -- hqx format will skip garbage lines; undoes some of
  15635. X *            -- gvr's work.  will now also recognize .dl format.
  15636. X */
  15637. X
  15638. SHAR_EOF
  15639. if test 1421 -ne "`wc -c < 'README.hexbin'`"
  15640. then
  15641.     echo shar: "error transmitting 'README.hexbin'" '(should have been 1421 characters)'
  15642. fi
  15643. fi
  15644. echo shar: "extracting 'README.crc'" '(237 characters)'
  15645. if test -f 'README.crc'
  15646. then
  15647.     echo shar: "will not over-write existing file 'README.crc'"
  15648. else
  15649. sed 's/^X//' << \SHAR_EOF > 'README.crc'
  15650. XThis code is based on the code described in README.ORIG.
  15651. XChanges are:
  15652. X1.    A program (makecrc) will create the different C source
  15653. X    files to do crc calculations.
  15654. X2.    The crc calculation method of binhex is added.
  15655. X3.    32 bit crc's are added.
  15656. X
  15657. SHAR_EOF
  15658. if test 237 -ne "`wc -c < 'README.crc'`"
  15659. then
  15660.     echo shar: "error transmitting 'README.crc'" '(should have been 237 characters)'
  15661. fi
  15662. fi
  15663. echo shar: "extracting 'README.crc.orig'" '(5926 characters)'
  15664. if test -f 'README.crc.orig'
  15665. then
  15666.     echo shar: "will not over-write existing file 'README.crc.orig'"
  15667. else
  15668. sed 's/^X//' << \SHAR_EOF > 'README.crc.orig'
  15669. X/* updcrc(3), crc(1) - calculate crc polynomials
  15670. X *
  15671. X * Calculate, intelligently, the CRC of a dataset incrementally given a 
  15672. X * buffer full at a time.
  15673. X * 
  15674. X * Usage:
  15675. X *     newcrc = updcrc( oldcrc, bufadr, buflen )
  15676. X *         unsigned int oldcrc, buflen;
  15677. X *         char *bufadr;
  15678. X *
  15679. X * Compiling with -DTEST creates a program to print the CRC of stdin to stdout.
  15680. X * Compile with -DMAKETAB to print values for crctab to stdout.  If you change
  15681. X *    the CRC polynomial parameters, be sure to do this and change
  15682. X *    crctab's initial value.
  15683. X *
  15684. X * Notes:
  15685. X *  Regards the data stream as an integer whose MSB is the MSB of the first
  15686. X *  byte recieved.  This number is 'divided' (using xor instead of subtraction)
  15687. X *  by the crc-polynomial P.
  15688. X *  XMODEM does things a little differently, essentially treating the LSB of
  15689. X * the first data byte as the MSB of the integer. Define SWAPPED to make
  15690. X * things behave in this manner.
  15691. X *
  15692. X * Author:    Mark G. Mendel, 7/86
  15693. X *        UUCP: ihnp4!umn-cs!hyper!mark, GEnie: mgm
  15694. X */
  15695. X
  15696. X/* The CRC polynomial.
  15697. X * These 4 values define the crc-polynomial.
  15698. X * If you change them, you must change crctab[]'s initial value to what is
  15699. X * printed by initcrctab() [see 'compile with -DMAKETAB' above].
  15700. X */
  15701. X    /* Value used by:                CITT    XMODEM    ARC      */
  15702. X#define    P     0xA001     /* the poly:    0x1021    0x1021    A001    */
  15703. X#define INIT_CRC 0L     /* init value:    -1    0    0    */
  15704. X#define SWAPPED         /* bit order:    undef    defined    defined */
  15705. X#define W    16     /* bits in CRC:16    16    16    */
  15706. X
  15707. X    /* data type that holds a W-bit unsigned integer */
  15708. X#if W <= 16
  15709. X#  define WTYPE    unsigned short
  15710. X#else
  15711. X#  define WTYPE   unsigned long
  15712. X#endif
  15713. X
  15714. X    /* the number of bits per char: don't change it. */
  15715. X#define B    8
  15716. X
  15717. Xstatic WTYPE crctab[1<<B] = /* as calculated by initcrctab() */ {
  15718. X0x0,  0xc0c1,  0xc181,  0x140,  0xc301,  0x3c0,  0x280,  0xc241,
  15719. X0xc601,  0x6c0,  0x780,  0xc741,  0x500,  0xc5c1,  0xc481,  0x440,
  15720. X0xcc01,  0xcc0,  0xd80,  0xcd41,  0xf00,  0xcfc1,  0xce81,  0xe40,
  15721. X0xa00,  0xcac1,  0xcb81,  0xb40,  0xc901,  0x9c0,  0x880,  0xc841,
  15722. X0xd801,  0x18c0,  0x1980,  0xd941,  0x1b00,  0xdbc1,  0xda81,  0x1a40,
  15723. X0x1e00,  0xdec1,  0xdf81,  0x1f40,  0xdd01,  0x1dc0,  0x1c80,  0xdc41,
  15724. X0x1400,  0xd4c1,  0xd581,  0x1540,  0xd701,  0x17c0,  0x1680,  0xd641,
  15725. X0xd201,  0x12c0,  0x1380,  0xd341,  0x1100,  0xd1c1,  0xd081,  0x1040,
  15726. X0xf001,  0x30c0,  0x3180,  0xf141,  0x3300,  0xf3c1,  0xf281,  0x3240,
  15727. X0x3600,  0xf6c1,  0xf781,  0x3740,  0xf501,  0x35c0,  0x3480,  0xf441,
  15728. X0x3c00,  0xfcc1,  0xfd81,  0x3d40,  0xff01,  0x3fc0,  0x3e80,  0xfe41,
  15729. X0xfa01,  0x3ac0,  0x3b80,  0xfb41,  0x3900,  0xf9c1,  0xf881,  0x3840,
  15730. X0x2800,  0xe8c1,  0xe981,  0x2940,  0xeb01,  0x2bc0,  0x2a80,  0xea41,
  15731. X0xee01,  0x2ec0,  0x2f80,  0xef41,  0x2d00,  0xedc1,  0xec81,  0x2c40,
  15732. X0xe401,  0x24c0,  0x2580,  0xe541,  0x2700,  0xe7c1,  0xe681,  0x2640,
  15733. X0x2200,  0xe2c1,  0xe381,  0x2340,  0xe101,  0x21c0,  0x2080,  0xe041,
  15734. X0xa001,  0x60c0,  0x6180,  0xa141,  0x6300,  0xa3c1,  0xa281,  0x6240,
  15735. X0x6600,  0xa6c1,  0xa781,  0x6740,  0xa501,  0x65c0,  0x6480,  0xa441,
  15736. X0x6c00,  0xacc1,  0xad81,  0x6d40,  0xaf01,  0x6fc0,  0x6e80,  0xae41,
  15737. X0xaa01,  0x6ac0,  0x6b80,  0xab41,  0x6900,  0xa9c1,  0xa881,  0x6840,
  15738. X0x7800,  0xb8c1,  0xb981,  0x7940,  0xbb01,  0x7bc0,  0x7a80,  0xba41,
  15739. X0xbe01,  0x7ec0,  0x7f80,  0xbf41,  0x7d00,  0xbdc1,  0xbc81,  0x7c40,
  15740. X0xb401,  0x74c0,  0x7580,  0xb541,  0x7700,  0xb7c1,  0xb681,  0x7640,
  15741. X0x7200,  0xb2c1,  0xb381,  0x7340,  0xb101,  0x71c0,  0x7080,  0xb041,
  15742. X0x5000,  0x90c1,  0x9181,  0x5140,  0x9301,  0x53c0,  0x5280,  0x9241,
  15743. X0x9601,  0x56c0,  0x5780,  0x9741,  0x5500,  0x95c1,  0x9481,  0x5440,
  15744. X0x9c01,  0x5cc0,  0x5d80,  0x9d41,  0x5f00,  0x9fc1,  0x9e81,  0x5e40,
  15745. X0x5a00,  0x9ac1,  0x9b81,  0x5b40,  0x9901,  0x59c0,  0x5880,  0x9841,
  15746. X0x8801,  0x48c0,  0x4980,  0x8941,  0x4b00,  0x8bc1,  0x8a81,  0x4a40,
  15747. X0x4e00,  0x8ec1,  0x8f81,  0x4f40,  0x8d01,  0x4dc0,  0x4c80,  0x8c41,
  15748. X0x4400,  0x84c1,  0x8581,  0x4540,  0x8701,  0x47c0,  0x4680,  0x8641,
  15749. X0x8201,  0x42c0,  0x4380,  0x8341,  0x4100,  0x81c1,  0x8081,  0x4040,
  15750. X} ;
  15751. X
  15752. XWTYPE
  15753. Xupdcrc( icrc, icp, icnt )
  15754. X    WTYPE icrc;
  15755. X    unsigned char *icp;
  15756. X    int icnt;
  15757. X{
  15758. X    register WTYPE crc = icrc;
  15759. X    register unsigned char *cp = icp;
  15760. X    register int cnt = icnt;
  15761. X
  15762. X    while( cnt-- ) {
  15763. X#ifndef SWAPPED
  15764. X    crc = (crc<<B) ^ crctab[(crc>>(W-B)) ^ *cp++];
  15765. X#else
  15766. X    crc = (crc>>B) ^ crctab[(crc & ((1<<B)-1)) ^ *cp++]; 
  15767. X#endif SWAPPED
  15768. X    }
  15769. X
  15770. X    return( crc );
  15771. X}
  15772. X
  15773. X#ifdef MAKETAB
  15774. X
  15775. X#include <stdio.h>
  15776. Xmain()
  15777. X{
  15778. X    initcrctab();
  15779. X}
  15780. X
  15781. Xinitcrctab()
  15782. X{
  15783. X    register  int b, i;
  15784. X    WTYPE v;
  15785. X
  15786. X    
  15787. X    for( b = 0; b <= (1<<B)-1; ++b ) {
  15788. X#ifndef SWAPPED
  15789. X    for( v = b<<(W-B), i = B; --i >= 0; )
  15790. X        v = v & ((WTYPE)1<<(W-1)) ? (v<<1)^P : v<<1;
  15791. X#else
  15792. X    for( v = b, i = B; --i >= 0; )
  15793. X        v = v & 1 ? (v>>1)^P : v>>1;
  15794. X#endif        
  15795. X    crctab[b] = v;
  15796. X
  15797. X    printf( "0x%lx,", v & ((1L<<W)-1L));
  15798. X    if( (b&7) == 7 )
  15799. X        printf("\n" );
  15800. X    else
  15801. X        printf("  ");
  15802. X    }
  15803. X}
  15804. X#endif
  15805. X
  15806. X#ifdef TEST
  15807. X
  15808. X#include <stdio.h>
  15809. X#include <fcntl.h>
  15810. X
  15811. X#define MAXBUF    4096
  15812. X
  15813. X
  15814. X
  15815. Xmain( ac, av )
  15816. X    int ac; char **av;
  15817. X{
  15818. X    int fd;
  15819. X    int nr;
  15820. X    int i;
  15821. X    char buf[MAXBUF];
  15822. X    WTYPE crc, crc2;
  15823. X
  15824. X    fd = 0;
  15825. X    if( ac > 1 )
  15826. X    if( (fd = open( av[1], O_RDONLY )) < 0 ) {
  15827. X        perror( av[1] );
  15828. X        exit( -1 );
  15829. X    }
  15830. X    crc = crc2 = INIT_CRC;
  15831. X
  15832. X    while( (nr = read( fd, buf, MAXBUF )) > 0 ) {
  15833. X    crc = updcrc( crc, buf, nr );
  15834. X    }
  15835. X
  15836. X    if( nr != 0 )
  15837. X    perror( "reading" );
  15838. X    else {
  15839. X    printf( "%lx\n", crc );
  15840. X    }
  15841. X
  15842. X#ifdef MAGICCHECK
  15843. X    /* tack one's complement of crc onto data stream, and
  15844. X       continue crc calculation.  Should get a constant (magic number)
  15845. X       dependent only on P, not the data.
  15846. X     */
  15847. X    crc2 = crc ^ -1L;
  15848. X    for( nr = W-B; nr >= 0; nr -= B ) {
  15849. X    buf[0] = (crc2 >> nr);
  15850. X    crc = updcrc(crc, buf, 1);
  15851. X    }
  15852. X
  15853. X    /* crc should now equal magic */
  15854. X    buf[0] = buf[1] = buf[2] = buf[3] = 0;
  15855. X    printf( "magic test: %lx =?= %lx\n", crc, updcrc(-1, buf, W/B));
  15856. X#endif MAGICCHECK
  15857. X}
  15858. X
  15859. X#endif
  15860. X****************************************************************************
  15861. X
  15862. SHAR_EOF
  15863. if test 5926 -ne "`wc -c < 'README.crc.orig'`"
  15864. then
  15865.     echo shar: "error transmitting 'README.crc.orig'" '(should have been 5926 characters)'
  15866. fi
  15867. fi
  15868. echo shar: "done with directory 'doc'"
  15869. cd ..
  15870. echo shar: "done with directory 'macutil'"
  15871. cd ..
  15872. exit 0
  15873. #    End of shell archive
  15874.